Reputation: 2473
This is my XMl: I want to print sth like this ,Numbering as shown 1. 2. only if "name" is ABC . I am having little difficulty in assigning a counter variable and incrementing it and then checking for a certain value in XSLT. Here is my code:
<Details>
<name>ABC</name>
<EFFECTIVEDATE>2010-04-30</EFFECTIVEDATE>
</Details>
<Details>
<name>EFG</name>
<EFFECTIVEDATE>2010-04-30</EFFECTIVEDATE>
</Details>
<Details>
<name>XYZ</name>
<EFFECTIVEDATE>2022-04-01</EFFECTIVEDATE>
</Details>
<Details>
<name>ABC</name>
<EFFECTIVEDATE>2022-04-01</EFFECTIVEDATE>
</Details>
<Details>
<name>ABC</name>
<EFFECTIVEDATE>2022-04-01</EFFECTIVEDATE>
</Details>
Here is XSL stylesheet:
<xsl:for-each select="Details">
</xsl:call-template name="DetaimTemplate">
</xsl:for-each>
<xsl:template name="DetaimTemplate">
</xsl:template>
Expected result
1.ABC
2.ABC
3.ABC
How can i print like 1.
2.
and so on
Upvotes: 1
Views: 2702
Reputation: 116992
Well, you could do simply:
<xsl:for-each select="Details[name='ABC']">
<xsl:value-of select="position()" />
<xsl:text>. ABC </xsl:text>
</xsl:for-each>
Of course, you will also need a well-formed input with a root element and a template matching that element to contain the above, before it can work.
Upvotes: 1
Reputation: 640
You haven't mentioned whether your output will be text or xml. I have provided the solution assuming you are expecting xml output. I have started from the point where your xslt parser is traversing over each of Details node
<xsl:template match="Details">
<xsl:if test="name='ABC'">
<t>
<xsl:value-of select="count(preceding-sibling::*[name='ABC']) + 1"/>
<xsl:text>.ABC</xsl:text>
</t>
</xsl:if>
</xsl:template>
Upvotes: 0