XSLT 2.0具有的功能http://www.w3.org/TR/2013/CR-xpath-functions-30-20130521/#func-deep-equal所以可以编写一个模板
<xsl:template match="parent[deep-equal(., preceding-sibling::parent[1])]">...</xsl:template>
处理那些parent
元素等于其前面的同级parent
。
如果你想用XSLT 1.0做到这一点,然后你用纯文本内容的子元素序列的简单的情况下,它应该足以编写模板
<xsl:template match="parent" mode="sig">
<xsl:for-each select="*">
<xsl:if test="position() > 1">|</xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
,然后使用它,如下所示:
<xsl:template match="parent">
<xsl:variable name="this-sig">
<xsl:apply-templates select="." mode="sig"/>
</xsl:variable>
<xsl:variable name="pre-sig">
<xsl:apply-templates select="preceding-sibling::parent[1]" mode="sig"/>
</xsl:variable>
<!-- now compare e.g. -->
<xsl:choose>
<xsl:when test="$this-sig = $pre-sig">...</xsl:when>
<xsl:otherwise>...</xsl:otherwise>
</xsl:choose>
</xsl:template>
对于更复杂的内容,你需要细化模板计算“签名”串的实施,你可能想在网上搜索,我相信Dimitre Novatchev已经张贴在早期,类似的问题的解决方案。
你想要什么输出? –
在我的数据中有30多个节点,我正在通过查看每个节点。我想知道当前父项的子节点何时与以前的父项不同。 E.G,它可以是X X X,然后是X X X,然后是Y X Y.我想知道这是什么时候发生的。 –