I’m using Saxon HE 9-4-0-3J. My intent is to use the select attribute on xsl:apply-templates to iterate over each <RECORD> element, but only a single <RECORD> element in the xml is being processed.
xml
<ENVELOPE>
<PRODUCT>
<HEAD><FLAG>No</FLAG></HEAD>
<BODY>
<RECORD><Value>9</Value></RECORD>
<RECORD><Value>10</Value></RECORD>
<MISC>9</MISC>
</BODY>
</PRODUCT>
xslt 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ENVELOPE">
<Interface>
<Data><xsl:apply-templates select="PRODUCT"/></Data>
</Interface>
</xsl:template>
<xsl:template match="PRODUCT">
<xsl:choose>
<xsl:when test="HEAD/FLAG='Yes'">
<xsl:attribute name="Match">Affirmative</xsl:attribute>
<xsl:apply-templates select="BODY/RECORD" mode="affr"/>
</xsl:when>
<xsl:when test="HEAD/FLAG='No'">
<xsl:attribute name="Match">Negative</xsl:attribute>
<xsl:apply-templates select="BODY/RECORD" mode="neg"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="RECORD" mode="affr">
<xsl:attribute name="Value"><xsl:value-of select="Value"/></xsl:attribute>
</xsl:template>
<xsl:template match="RECORD" mode="neg">
<xsl:attribute name="Value"><xsl:value-of select="Value"/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Output
<Interface>
<Data Match="Negative" Value="9"/> <!-- this line doesn't appear, I want it to -->
<Data Match="Negative" Value="10"/>
</Interface>
The
<DATA...>output tag is generated when you match<ENVELOPE...>, so there can only be one of these output. Any<xsl:attribute>directives merely add to this output tag, with later values overwriting earlier ones.You must explicitly generate the
DATAtags you want output, as in: