title: XSLT Transform multiple files from subdirectory
body: <p>I have created a XSLT file that can transform a single XML file. However, I have several hundred directories with multiple xml files. Is there a way in XSLT to transform all these files. I am using the collection function to get a list of all files. But, not sure how to apply the transform now.</p>
  
  <p>Here is my example XSLT file. Basically, I want to loop through all the xml files and apply the template table on the individual file. The output of all these transforms needs to be in one single flat text file.</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="http://whatever"&gt;
  
  &lt;xsl:output method="text" encoding="ISO-8859-1"/&gt;
      &lt;xsl:template name="process"&gt;
          &lt;xsl:variable name="files" select="collection('file:///C:/files/testResults?select=*.xml;recurse=yes')"/&gt;
          &lt;xsl:for-each select="$files"&gt;
              &lt;xsl:if test="(not(contains(document-uri(.), 'SuiteSetUp'))) and (not(contains(document-uri(.), 'SuiteTearDown')))"&gt;
                  &lt;xsl:value-of select="tokenize(document-uri(.), '/')[last()]"&gt;&lt;/xsl:value-of&gt;
                  &lt;xsl:apply-templates select="/testResults/result/tables/table[14]"&gt;
                      &lt;xsl:with-param name="title" select="/testResults/rootPath"&gt;&lt;/xsl:with-param&gt;
                  &lt;/xsl:apply-templates&gt;
                  &lt;xsl:apply-templates select="/testResults/result/tables/table[15]"/&gt;
              &lt;/xsl:if&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="table"&gt;
      &lt;xsl:param name="testName"&gt;&lt;/xsl:param&gt;
          &lt;xsl:for-each select="row"&gt;
              &lt;xsl:if test="position() &gt; 2"&gt;
                  &lt;xsl:variable name="choices" select="col[2]"&gt;&lt;/xsl:variable&gt;
                  &lt;xsl:if test="contains($choices, 'fail')"&gt;
                      &lt;xsl:value-of  select="$testName"&gt;&lt;/xsl:value-of&gt;
                      &lt;xsl:text&gt;|&lt;/xsl:text&gt;
                      &lt;xsl:value-of select="col[1]"&gt;&lt;/xsl:value-of&gt;
                      &lt;xsl:text&gt;|&lt;/xsl:text&gt;
                      &lt;xsl:value-of select="foo:getCorrectChoices(col[2])"&gt;&lt;/xsl:value-of&gt;
                      &lt;xsl:text&gt;|&lt;/xsl:text&gt;
                      &lt;xsl:value-of select="foo:getExpectedChoices(col[2])"&gt;&lt;/xsl:value-of&gt;
                      &lt;xsl:text&gt;|&lt;/xsl:text&gt;
                      &lt;xsl:call-template name="NewLine"/&gt;
                  &lt;/xsl:if&gt;
              &lt;/xsl:if&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name="NewLine"&gt;
          &lt;xsl:text&gt;&amp;#xA;&lt;/xsl:text&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:function name="foo:getCorrectChoices"&gt;
          &lt;xsl:param name="content"&gt;&lt;/xsl:param&gt;
          &lt;xsl:analyze-string select="$content" regex="\[(\[.+?\])\] fail"&gt;
              &lt;xsl:matching-substring&gt;
                  &lt;xsl:value-of select="regex-group(1)"&gt;&lt;/xsl:value-of&gt;
              &lt;/xsl:matching-substring&gt;
          &lt;/xsl:analyze-string&gt;
      &lt;/xsl:function&gt;
      &lt;xsl:function name="foo:getExpectedChoices"&gt;
          &lt;xsl:param name="content"&gt;&lt;/xsl:param&gt;
          &lt;xsl:analyze-string select="$content" regex="fail\(expected \[(\[.+?\])\]"&gt;
              &lt;xsl:matching-substring&gt;
                  &lt;xsl:value-of select="regex-group(1)"&gt;&lt;/xsl:value-of&gt;
              &lt;/xsl:matching-substring&gt;
          &lt;/xsl:analyze-string&gt;
      &lt;/xsl:function&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>