title: XSLT: How to get file names from a certain directory?
body: <p>Is there a function in XSLT that can takes in a directory path and gives back all the files in it??</p>
  
  <p>I have a xml file now reads like this</p>
  
  <pre><code>&lt;filelist&gt;
      &lt;file&gt;fileA.xml&lt;/file&gt;
      &lt;file&gt;fileB.xml&lt;/file&gt;
  &lt;/filelist&gt;
  </code></pre>
  
  <p>Now, there's directory called <code>dir</code>, has files <code>fileX.xml</code>, <code>fileY.xml</code> and a bunch of other xml files in it. I want to add these files on to the orginal xml file, so that I can get:</p>
  
  <pre><code>&lt;filelist&gt;
      &lt;file&gt;fileA.xml&lt;/file&gt;
      &lt;file&gt;fileB.xml&lt;/file&gt;
      &lt;file&gt;fileX.xml&lt;/file&gt;
      &lt;file&gt;fileY.xml&lt;/file&gt;
      .... &lt;!-- other files --&gt;
  &lt;/filelist&gt;
  </code></pre>
  
  <p>Is there an XSLT way to do this?? something that takes in a dir root, and is able to iterator through all of the files in it?? And then I could just call something like:</p>
  
  <pre><code>&lt;xsl:element name = file &gt;
       &lt;xsl:copy&gt; &lt;!--whatever file name--&gt; &lt;xsl:copy&gt;
  &lt;/xsl:element&gt;0
  </code></pre>
  
  <h2>[Edit-solution]</h2>
  
  <p>all of the answers were very helpful. I ended up finding an external solution (using saxon). I thought it may be helpful for other people to post my solution here, although it is very specific to my own situation. </p>
  
  <p>I use Ant to build a java web app and need to translate some xml files before deployment. Hence, I was using the <code>xslt</code> task to do the job by adding the "saxon9.jar" in the classpath. And in my xsl file, I just did something like this:</p>
  
  <pre><code>&lt;xsl:for-each select="collection('../dir/?select=*.xml')" &gt;
       &lt;xsl:element name='file'&gt;
          &lt;xsl:value-of select="tokenize(document-uri(.), '/')[last()]"/&gt;
       &lt;/xsl:element&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>