xml - How can I split street and house number from address field in XSLT? -


how can separate via xslt street , house number? need split address string 2 nodes using xslt. so, example,

<customer>     <shippingaddress>test street 32a-33b</shippingaddress>  ... </customer> 

should following transformation:

<customer>  <street>test street</street>  <houseno>32a-33b</houseno>  </customer> 

i think right approach split first digit in string. idea?

in xslt 2.0, can use analyze-string use regex split string.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0">     <xsl:output method="xml" indent="yes" />      <xsl:template match="shippingaddress">         <xsl:analyze-string select="." regex="^(\d+)(\d.*)$">             <xsl:matching-substring>                 <street><xsl:value-of select="normalize-space(regex-group(1))" /></street>                 <houseno><xsl:value-of select="regex-group(2)" /></houseno>             </xsl:matching-substring>         </xsl:analyze-string>     </xsl:template>      <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates select="@*|node()"/>         </xsl:copy>     </xsl:template> </xsl:stylesheet> 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -