如何防止重复条目进入列表,然后理想地对列表进行排序?我在做什么,是什么时候缺少某一级别的信息,从低于它的级别获取信息,到上面的级别构建缺失的列表。目前,我有类似XML这样:如何防止XSL中的重复项?
<c03 id="ref6488" level="file">
<did>
<unittitle>Clinic Building</unittitle>
<unitdate era="ce" calendar="gregorian">1947</unitdate>
</did>
<c04 id="ref34582" level="file">
<did>
<container label="Box" type="Box">156</container>
<container label="Folder" type="Folder">3</container>
</did>
</c04>
<c04 id="ref6540" level="file">
<did>
<container label="Box" type="Box">156</container>
<unittitle>Contact prints</unittitle>
</did>
</c04>
<c04 id="ref6606" level="file">
<did>
<container label="Box" type="Box">154</container>
<unittitle>Negatives</unittitle>
</did>
</c04>
</c03>
我然后采用下列XSL:
<xsl:template match="c03/did">
<xsl:choose>
<xsl:when test="not(container)">
<did>
<!-- If no c03 container item is found, look in the c04 level for one -->
<xsl:if test="../c04/did/container">
<!-- If a c04 container item is found, use the info to build a c03 version -->
<!-- Skip c03 container item, if still no c04 items found -->
<container label="Box" type="Box">
<!-- Build container list -->
<!-- Test for more than one item, and if so, list them, -->
<!-- separated by commas and a space -->
<xsl:for-each select="../c04/did">
<xsl:if test="position() > 1">, </xsl:if>
<xsl:value-of select="container"/>
</xsl:for-each>
</container>
</did>
</xsl:when>
<!-- If there is a c03 container item(s), list it normally -->
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
但我发现了的
<container label="Box" type="Box">156, 156, 154</container>
当什么了 “容器” 的结果我想要的是
<container label="Box" type="Box">154, 156</container>
是低是我试图得到的全部结果:
<c03 id="ref6488" level="file">
<did>
<container label="Box" type="Box">154, 156</container>
<unittitle>Clinic Building</unittitle>
<unitdate era="ce" calendar="gregorian">1947</unitdate>
</did>
<c04 id="ref34582" level="file">
<did>
<container label="Box" type="Box">156</container>
<container label="Folder" type="Folder">3</container>
</did>
</c04>
<c04 id="ref6540" level="file">
<did>
<container label="Box" type="Box">156</container>
<unittitle>Contact prints</unittitle>
</did>
</c04>
<c04 id="ref6606" level="file">
<did>
<container label="Box" type="Box">154</container>
<unittitle>Negatives</unittitle>
</did>
</c04>
</c03>
在此先感谢您的帮助!
很好的问题(+1)的
separator
属性。查看我对XSLT 1.0解决方案的回答,该解决方案比当前选定的XSLT 2.0解决方案更短。 :) – 2010-04-20 13:26:48