xml - Take the value next to the last in xslt -


<address> 1234road unit 5 lane town, city so1d 23z customer no. 12321312312 </address>  <address> 21321311234road 1234road unit 5 lane town, city so1d 23z customer no. 12321312312 </address> 

can me take value of postcode before customer no.?

<xsl:value-of select="substring-before(substring-after(substring-after(substring-after(address,'&#10;'),'&#10;'),'&#10;'),'&#10;')"/> 

i have used above not going work on second example. need find way take next last.

note: there line breaks (crlf) between each line.

any appreciated

one possible way create recursive "substring-after-last" named template, , use passing in substring occurs before "customer no. "

try xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">     <xsl:output method="text" indent="yes" />      <xsl:template match="address">         <xsl:call-template name="substring-after-last">             <xsl:with-param name="text" select="$excust" />             <xsl:with-param name="arg" select="'&#10;'" />         </xsl:call-template>     </xsl:template>      <xsl:template name="substring-after-last">         <xsl:param name="text" />         <xsl:param name="arg" />          <xsl:variable name="after" select="substring-after($text, $arg)" />         <xsl:choose>              <xsl:when test="contains($after, $arg)">                 <xsl:call-template name="substring-after-last">                     <xsl:with-param name="text" select="$after" />                     <xsl:with-param name="arg" select="$arg" />                 </xsl:call-template>             </xsl:when>             <xsl:otherwise>                 <xsl:value-of select="$after" />             </xsl:otherwise>         </xsl:choose>     </xsl:template> </xsl:stylesheet> 

if dealing uk postcodes, vary between 6 , 8 characters in length (including space), via crude method....

<xsl:variable name="excust" select="substring-before(., '&#10;customer no. ')" /> <xsl:value-of select="substring-after(substring($excust, string-length($excust) - 8, 9), '&#10;')" /> 

this bit of hack though, , fail if preceding town/city 1 character in length!


Comments