2

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

2
  • Did you really mean "Greenwich Avenue" in your wished output, and not "Greenwich Avenue 20"? Commented Dec 7, 2011 at 13:10
  • Just ,,Greenwich Avenue" Commented Dec 7, 2011 at 15:36

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.