Subject: RE: [xsl] FW: XSL to split a concatenated XML string From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 14 Mar 2006 13:27:43 -0000 |
> I have given the substring function a go as shown below. I don't see the substring() function here, I only see substring-before() and substring-after(). Michael Kay http://www.saxonica.com/ > But it puts everything in the second column. > > I am trying to get it to split the string before and after the space. > I think what may be happening is that I'm not specifying the space > correctly by saying substring-before($str, ' ') > > <xsl:call-template name="StandNumber"> > <xsl:with-param name="str" select="."/> > </xsl:call-template> > </xsl:template> > > <xsl:template name="StandNumber"> > <xsl:param name="str"/> > <xsl:choose> > <xsl:when test="contains($str,' ')"> > <table cellpadding="0" cellspacing="10"> > <tr> > <td width="200"><a href="{substring-before($str,' ')}"> > <xsl:value-of select="substring-before($str,' ')"/></a> > </td> > <td width="200"><a href="{substring-after($str,' ')}"> > <xsl:value-of select="substring-after($str,' ')"/></a> > </td> > </tr> > </table> > > > </xsl:when> > > </xsl:choose> > > </xsl:template> > > > > Output = > > STAND NUMBER : STAND ADDRESS : > > T51000000000000000000000000 NONE,. > T51000000000010000000000000 31 VAN STRAAT,. > T51000000000020000000000000 29 VAN STRAAT,. > > Required = > > STAND NUMBER : STAND ADDRESS : > > T51000000000000000000000000 NONE,. > T51000000000010000000000000 31 VAN STRAAT,. > T51000000000020000000000000 29 VAN STRAAT,. > > > ________________________________ > > From: Luke Stedman [mailto:luke.stedman@xxxxxxxxx] > Sent: 14 March 2006 01:28 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx; Cave, Neil; > neil.cave@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] FW: XSL to split a concatenated XML string > > > > You can use the substring-before() and substring-after() functions... > > <xsl:variable name=3D"OPTION" select=3D"/optionList1/option"/> > > <xsl:variable name=3D"STAND_NO" > select=3D"substring-before($OPTION,'&space;')"/> > <xsl:variable name=3D"ADDRESS" > select=3D"substring-after($OPTION,'&space;') "/> > > Though as you addresses have spaces in them it could cause an issue, > from experience I think it uses the first instance of the > text string to > determine where it should split the string. > > ...or... > > You can use the substring-before(), substring() and string-length() > functions... > > <xsl:variable name=3D"OPTION" select=3D"/optionList1/option"/> > <xsl:variable name=3D"STAND_NO" > select=3D"substring-before($OPTION,'&space;')"/> > <xsl:variable name=3D"ADDRESS" > select=3D"substring($OPTION,29,string-length($OPTION) - 29)"/> > > This should work, though you may need to tweak the values in the > substring() and string-length() calls > > Cheers > Stedders > > > On 14/03/06, Cave, Neil <Neil.Cave@xxxxxxxxxxxxxx> wrote: > > Hi XSL Ninjas > > I have to split a list of concatenated XML strings and display > it in 2 > fields > > The xml looks like > > <?xml version="1.0" encoding="UTF-8" ?> > <optionList1> > <option>T51000000000000000000000000 NONE,.</option> > <option>T51000000000010000000000000 31 VAN STRAAT,.</option> > <option>T51000000000020000000000000 29 VAN > STRAAT,.</option> > <option>T51000000000030000000000000 36 BECKERWEG,.</option> > <option>T51000000000040000000000000 34 BECKERWEG,.</option> > </optionList1> > > And I need to display 2 distinct columns (in HTML).... > > Stand Number Address > > T51000000000000000000000000 NONE,. > T51000000000010000000000000 31 VAN STRAAT,. > T51000000000020000000000000 29 VAN STRAAT,. > T51000000000030000000000000 36 BECKERWEG,. > T51000000000040000000000000 34 BECKERWEG,. > > There will always be 14 occurrences of option within optionList1 > the > stand number will always be 27 characters followed by space. > > What's the best way to tackle this? > > Regards > Neil
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] FW: XSL to split a concat, Cave, Neil | Thread | RE: [xsl] FW: XSL to split a concat, Cave, Neil |
[xsl] Mapping Values., Amal | Date | RE: [xsl] FW: XSL to split a concat, Michael Kay |
Month |