Listing nodes from different for-each loop search in one variable/sequence/group
I have a problem which i don't know the solution to. I am using xslt 1.0.
My task is as following:
I have a file where there are url to different .xml files. My job is to, get the names of these files, and then iterate through each of these files looking for a tag <Genre>
. So it can be that, in the first file I find 3 <Genre>
elements, in the 2nd 1 <Genre>
element ... and so on till the n-th file.
After gathering all the <Genre>
elements from all the files, I need to sort them (they hold a string info in them, which is like their name). To sort them, I need to have ALL the <Genre>
elements in ONE varibale/group/sequence, so that I can apply the <xsl:sort>
on them.
But I don't know, how I can add/union/concatenate the <Genre>
elements that I find in every loop from each of the files :(
Please please help ... I have tried now for 9 hours with no result.
The code looks approximately like below:
The xml file with the file names
<document-properties>
<source-documents>
<document name="Input/Commandline.xml"/>
<document name="Input/Outputfiles.xml"/>
<document name="Input/PrimaryFunctionalities.xml"/>
<document name="Input/Requirements.xml"/>
<document开发者_Python百科 name="Input/UsecaseTree.xml"/>
<document name="Input/CurrentDate.xml"/>
<document name="CommentFiles/VWCC_Test.xml"/>
</source-documents>
</document-properties>
And I am doing the following in my .xsl:
<xsl:for-each select="/document-properties/source-documents/*">
<xsl:for-each select="document(@name)/descendant::newTerm">
<xsl:variable name="CurrentNewTerm" select="."/>
<w:tr wsp:rsidR="00000000">
<w:tblPrEx>
<w:tblCellMar>
<w:top w:w="0" w:type="dxa" />
<w:bottom w:w="0" w:type="dxa" />
</w:tblCellMar>
</w:tblPrEx>
<w:tc>
<w:tcPr>
<w:tcW w:w="2480" w:type="dxa" />
</w:tcPr>
<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t>
<xsl:value-of select="$CurrentNewTerm"/>
</w:t>
</w:r>
</w:p>
</w:tc>
<xsl:variable name="abbrvFileName" select="/document-properties/abbreviation-document/*[@name]"/>
<xsl:for-each select="document($abbrvFileName)/descendant::term">
</xsl:for-each>
<w:tc>
<w:tcPr>
<w:tcW w:w="2480" w:type="dxa" />
</w:tcPr>
<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t>
<xsl:value-of select="$CurrentNewTerm"/>
</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</xsl:for-each>
</xsl:for-each>
As told before, in this way I get the tags of one file at once ... but I need a way to save the "found" tags of each for-each loop in a list/group/sequence ... so that I can do a SORT on ALL the tags of all the files as one list.
How are you invoking the XSLT processing from? commandline? some programming language?
The simple approach is to concatenate all the files into one single large xml file and then pass the single large xml file into XSLT.
The technique/code to do the concatenation is going to vary depending on the language you are invoking from.
This is perfectly straightforward to do with something like this:
<xsl:for-each select="document(.//url)//Genre">
<xsl:sort select="StringInfo">
...
</xsl:for-each>
精彩评论