using XSLT 1.0
.
<xsl:for-each select="*">
<xsl:variable name="xxxx" select="@name" />
<xsl:if test="../../../../fieldMap/field[@name=$xxxx]">...
<xsl:if test="position() != last()">////this is not work correctly as last() number is actual last value of for loop and position() is based on if condition.
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
can you suggest me how can i remove last ',
' here ?
position()
and last()
should be based on the loop, and not the xsl:if
. What I think you are saying is that you are actually wanting to check if this is the last element for which the xsl:if
is true, as such an element may not actually be the last element in the loop.
I would suggest combining your xsl:for-each
and xsl:if
into one, and selecting only those elements for which the condition is true. That way you should then be able to check the position in the way you were expecting
<xsl:for-each select="*[@name = ../../../../fieldMap/field/@name]">
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With