我有一个这样的文件:
<?xml version="1.0" encoding="utf-8"?>
<Zthes>
<term>
<termId>1</termId>
<termUpdate>Add</termUpdate>
<termName>Science, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId>OMITERM9998</termId>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>2</termId>
<termUpdate>Add</termUpdate>
<termName>Sciences, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId>OMITERMO9999</termId>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>OMITERMO9998</termId>
<termUpdate>Add</termUpdate>
<termName>Biological Sciences</termName>
<termType>Pt</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
</term>
<term>
<termId>OMITERMO9999</termId>
<termUpdate>Add</termUpdate>
<termName>Biological Sciences</termName>
<termType>Pt</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
</term>
</Zthes>
是否可以编写一个经过并合并所有Pts的xlst?在这种情况下,这将导致使用相同Pt项的第二项名称。他们使用的ID并不重要。每个Nd都会引用一个Pt,而不是每个Pt都会有ND引用它,并且Pts可以有多个Nds引用它们
感谢您提出任何指示,我对这些事情毫无希望!
编辑:输出为:
<?xml version="1.0" encoding="utf-8"?>
<Zthes>
<term>
<termId>1</termId>
<termUpdate>Add</termUpdate>
<termName>Science, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId>OMITERM9998</termId>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>2</termId>
<termUpdate>Add</termUpdate>
<termName>Sciences, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId>OMITERMO9998</termId>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>OMITERMO9998</termId>
<termUpdate>Add</termUpdate>
<termName>Biological Sciences</termName>
<termType>Pt</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
</term>
</Zthes>
使得2 Nd项与具有相同名称但不同ID的2个Pt项的关系被组合成具有仅与一个Pt项的关系的2个Nd项。只要将关系合并到第一个PT中,就可以删除第二个PT,这样就不会有重复但关系仍然完好无损?
答案 0 :(得分:1)
我写了以下样式表:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="k1" match="term[termType = 'Pt']" use="termName"/>
<xsl:key name="k2" match="term[termType = 'Pt']" use="termId"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="term[termType = 'Pt'][not(generate-id() = generate-id(key('k1', termName)[1]))]"/>
<xsl:template match="term[termType = 'Nd']/relation/termId">
<xsl:copy>
<xsl:value-of select="key('k1', key('k2', .)/termName)[1]/termId"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
适用于
<?xml version="1.0" encoding="utf-8"?>
<Zthes>
<term>
<termId>1</termId>
<termUpdate>Add</termUpdate>
<termName>Science, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId>OMITERM9998</termId>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>2</termId>
<termUpdate>Add</termUpdate>
<termName>Sciences, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId>OMITERMO9999</termId>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>OMITERMO9998</termId>
<termUpdate>Add</termUpdate>
<termName>Biological Sciences</termName>
<termType>Pt</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
</term>
<term>
<termId>OMITERMO9999</termId>
<termUpdate>Add</termUpdate>
<termName>Biological Sciences</termName>
<termType>Pt</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
</term>
</Zthes>
输出
<?xml version="1.0" encoding="utf-8"?><Zthes>
<term>
<termId>1</termId>
<termUpdate>Add</termUpdate>
<termName>Science, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId/>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>2</termId>
<termUpdate>Add</termUpdate>
<termName>Sciences, Biological</termName>
<termType>Nd</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
<relation>
<relationType>USE</relationType>
<termId>OMITERMO9998</termId>
<termName>Biological Sciences</termName>
</relation>
</term>
<term>
<termId>OMITERMO9998</termId>
<termUpdate>Add</termUpdate>
<termName>Biological Sciences</termName>
<termType>Pt</termType>
<termStatus>Active</termStatus>
<termApproval>Approved</termApproval>
<termCreatedDate>20110414T07:23:26</termCreatedDate>
<termCreatedBy>admin</termCreatedBy>
<termModifiedDate>20110414T07:35:54</termModifiedDate>
<termModifiedBy>admin</termModifiedBy>
<termAttribute label="A-Z Entry"/>
</term>
</Zthes>
所以没有正确解决一个交叉引用,但我认为问题不在于XSLT,而在于您的数据所在的位置<termId>OMITERM9998</termId>
,而<termId>OMITERMO9998</termId>
的前导0
。这有帮助吗?真实数据中的ID是否更好?或者您是否需要编码以去除前导零以匹配/交叉引用元素?