列出一个变量/序列/组中不同 for-each 循环搜索的节点
我有一个问题,我不知道解决方案。我正在使用 xslt 1.0。
我的任务如下:
我有一个文件,其中包含不同 .xml 文件的 url。我的工作是获取这些文件的名称,然后遍历每个文件以查找标签
。因此,在第一个文件中,我可能会找到 3 个
元素,在第二个
元素中,依此类推,直到第 n 个文件。
从所有文件中收集所有
元素后,我需要对它们进行排序(它们包含一个字符串信息,就像它们的名字一样)。为了对它们进行排序,我需要将所有
元素放在一个变量/组/序列中,以便我可以将
应用于他们。
但我不知道如何添加/联合/连接在每个文件的每个循环中找到的
元素:(
请帮忙...我已经尝试过现在 9 小时没有结果。
代码如下所示:
带有文件名的 xml 文件
<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 name="Input/UsecaseTree.xml"/>
<document name="Input/CurrentDate.xml"/>
<document name="CommentFiles/VWCC_Test.xml"/>
</source-documents>
</document-properties>
我正在 .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>
如前所述,通过这种方式,我可以一次获取一个文件的标签。 ..但我需要一种方法将每个 for-each 循环的“找到”标签保存在列表/组/序列中...以便我可以将所有文件的所有标签作为一个列表进行排序。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您如何调用 XSLT 处理?命令行?某种编程语言?
一种简单的方法是将所有文件连接成一个大的 xml 文件,然后将该单个大的 xml 文件传递到 XSLT。
进行串联的技术/代码将根据您调用的语言而有所不同。
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: