title: Using a variable as part of a XPath selection
body: <p>I'm looking to use a variable as part of an XPath expression.</p>
  
  <p>My problem might be the msxsl node-set function... not sure. But don't let that cloud your judgement... read on...</p>
  
  <p>I'm using a .NET function to load up the content file, which is passed in via bespoke XML content. The <code>@file</code> results in an XML file.</p>
  
  <p>The bespoke XML the sits on the page looks like :</p>
  
  <pre><code>&lt;control name="import" file="information.xml" node="r:container/r:group[@id='set01']/r:item[1]" /&gt;
  </code></pre>
  
  <p>The XSL looks like :</p>
  
  <pre><code>&lt;xsl:variable name="document"&gt;
      &lt;xsl:copy-of select="ext:getIncludedContent(@file)" /&gt;
  &lt;/xsl:variable&gt;
  </code></pre>
  
  <p>I'm then translating this to a node-set so I can query the document</p>
  
  <pre><code>&lt;xsl:variable name="preset-xml" select="msxsl:node-set($document)" /&gt;   
  </code></pre>
  
  <p>The source file I am loading in looks like : </p>
  
  <pre><code>&lt;container&gt;
      &lt;group id="set01"&gt;
          &lt;item&gt;value01&lt;/item&gt;
          &lt;item&gt;value02&lt;/item&gt;
          &lt;item&gt;value03&lt;/item&gt;
      &lt;/group&gt;
      &lt;group id="set02"&gt;
          &lt;item&gt;value04&lt;/item&gt;
          &lt;item&gt;value05&lt;/item&gt;
      &lt;/group&gt;                    
  &lt;/container&gt;
  </code></pre>
  
  <p>It works up until this point. I can see the source file being brought thru and output as XML.</p>
  
  <p>My problem comes in when I am trying to query the source file with an XPath expression fed in from the content.</p>
  
  <p>I've tried :</p>
  
  <pre><code>&lt;xsl:value-of select="$preset-xml/@node" /&gt;
  </code></pre>
  
  <p>Clearly that doesn't work as it looks for @node as a direct child of the loaded in XML.</p>
  
  <p>I've tried :</p>
  
  <pre><code>&lt;xsl:variable name="node" select="@node" /&gt;
  &lt;xsl:value-of select="$preset-xml/$node" /&gt;
  </code></pre>
  
  <p>But it doesn't like the second variable.</p>
  
  <p>I've tried concat($preset-xml,'/',$node), but that still draws out the entire document in the result.</p>
  
  <p>The only way I can get this working at the moment is to write out the full expression in the template :</p>
  
  <pre><code>&lt;xsl:value-of select="$preset-xml/r:container/r:group[@id='set01']/r:item[1]" /&gt;
  </code></pre>
  
  <p>Which correctly brings thru <code>value01</code></p>
  
  <p>But that is then a hard coded solution.
  I want to develop a solution which can be manipulated from the content to suit any sort of imported content, with the parameters declared in the content file.</p>
  
  <p>p.s. I'm using XSLT 1.0 because the tech admin won't change the Microsoft parser to support later versions of XSL, so any solution would need to be written with that in mind.</p>