Reputation: 579
I need to choose string from XML element Address
Here is my XML file
<table>
<row>
<address>Greenwich Avenue 20, New York</address>
</row>
</table>
Here is my XSLT file
<xsl:for-each select="table/row">
<tr>
<td>
<xsl:value-of select="address"/>
</td>
</tr>
</xsl:for-each>
Here is my wished output
Greenwich Avenue
Or
New York
Thank you
Upvotes: 2
Views: 345
Reputation: 243469
This transformation shows how to produce either of the two strings:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="address">
<xsl:value-of select=
"translate(substring-before(., ','),
'01234567890', ''
)
"/>
=============
<xsl:value-of select="substring-after(., ',')"/>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<table>
<row>
<address>Greenwich Avenue 20, New York</address>
</row>
</table>
the wanted two strings are obtained as the result of evaluating specific XPath expressions -- then output:
Greenwich Avenue
=============
New York
Upvotes: 1