この XSLT 1.0 スタイルシート:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="/payments">
<xsl:apply-templates select="payment"/>
</xsl:template>
<!-- Matches payment elements with the same reference number as the first preceding sibling payment element. -->
<xsl:template match="payment[preceding-sibling::payment[1]/referenceNumber = current()/referenceNumber]">
Same reference number.
</xsl:template>
<!-- All other payment elements, including the very first one. -->
<xsl:template match="payment">
Different reference number.
</xsl:template>
</xsl:stylesheet>
サンプルの入力 XML に適用すると、次のようになります。
<payments>
<payment>
<referenceNumber>150001</referenceNumber>
<amount>770.55</amount>
</payment>
<payment>
<referenceNumber>150001</referenceNumber>
<amount>880.66</amount>
</payment>
<payment>
<referenceNumber>150002</referenceNumber>
<amount>4500.00</amount>
</payment>
</payments>
次の出力 XML が生成されます。
Different reference number.
Same reference number.
Different reference number.