XSL根据xml记录文件对一组记录进行子集化

时间:2012-07-25 10:24:29

标签: xslt

我有一个大型XML文件和另一个小型XML文件,其名称与某些大型XML文件的某个属性值相匹配。我想使用小型文件创建大型XML文件的记录子集。我的XSL尝试是这样的

<xsl:stylesheet xmlns:t="http://www.xyz.com/xml/Fixit" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="t:Fixit[.//t:Name[(@OrganisationName!=document('single_include.xml')//OrganisationName)]]"></xsl:template>
</xsl:stylesheet>

我的名为“single_include.xml”的小型XML文件就像这样

<ListOfOrganisationName>
<OrganisationName>
The first organisation
</OrganisationName>
<OrganisationName>
The second organisation
</OrganisationName>
</ListOfOrganisationName>

它似乎仅适用于第一张唱片。有什么想法吗?

希望这是有道理的。

1 个答案:

答案 0 :(得分:0)

“排除”模板中的内部谓词

(@OrganisationName!=document('single_include.xml')//OrganisationName)
如果OrganisationName中的任何 single_include.xml不等于当前元素的OrganisationName属性,则

为真。这将排除“第二个组织”,因为过滤文件(“第一个组织”)中存在OrganisationName,它不相等。相反,你可能想要

not(@OrganisationName=document('single_include.xml')//OrganisationName)

仅当OrganisationName中的没有 single_include.xml等于当前元素的OrganisationName属性时才会成立。 XPath规范在section 3.4中指出

  

注意:如果$x绑定到某个节点集,那么$x="foo"not($x!="foo")不一样

相关问题