I have to validate and concatenate multiple variable after validating them.
<xsl:variable name="val1" select="//xpath"/>
<xsl:variable name="val2" select="//xpath"/>
<xsl:variable name="val3" select="//xpath"/>
<xsl:variable name="val4" select="//xpath"/>
<xsl:variable name="val5" select="//xpath"/>
Is there any template available for this or anyone can help me doing this.
Update from comments
I want to concatenate five values like this: Address, Address1, City, State, Zipcode
. If Address
is missing I'll get an output like this ", address1, city, state, zipcode
". I want to get rid of that first comma.
<xsl:variable name="__add" select="translate(//*/text()[contains(., 'Address')]/following::td[contains(@class, 'fnt')][1], ',', '')"/>
<xsl:variable name="address">
<xsl:for-each select="$__add | //*/text()[contains(., 'City')]/following::td[contains(@class, 'fnt')][1] | //*/text()[contains(., 'State')]/following::td[contains(@class, 'fnt')][1] | //*/text()[contains(., 'Pincode')]/following::td[contains(@class, 'fnt')][1]">
<xsl:value-of select="concat(substring(', ', 1 div (position()!=1)), .)"/>
</xsl:for-each>
</xsl:variable>
In XSLT 2.0: string-join((Address, Address1, City, State, Zipcode), ',')
In XSLT 1.0, provided you're outputting the results in document order:
<xsl:for-each select="Address | Address1 | City | State | Zipcode">
<xsl:if test="position() != 1">, </xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
If not in document order, then like many things in XSLT 1.0, it's probably rather tedious.
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