RE: [xsl] FW: XSL to split a concatenated XML string

Subject: RE: [xsl] FW: XSL to split a concatenated XML string
From: "Cave, Neil" <Neil.Cave@xxxxxxxxxxxxxx>
Date: Tue, 14 Mar 2006 12:52:11 +0100
The XSl syntax (below) is returning the error...

Reference to undefined entity 'space'. Error processing resource
/stand.xsl'.

       On this line ===>>      <td width="200"><a
href="{substring-before($str,'&space;')}">



  <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,'&space;')}">
	         <xsl:value-of
select="substring-before($str,'&space;')"/></a>
              </td>
	      <td width="200"><a
href="{substring-after($str,'&space;')}">
	           <xsl:value-of
select="substring-after($str,'&space;')"/></a>
              </td>
           </tr>
	</table>



   </xsl:when>

  </xsl:choose>

</xsl:template>

-----Original Message-----
From: Cave, Neil [mailto:Neil.Cave@xxxxxxxxxxxxxx]
Sent: 14 March 2006 01:38 PM
To: Luke Stedman
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] FW: XSL to split a concatenated XML string

I have given the substring function a go as shown below.
It was putting everything in the second column.

I was trying to get it to split the string before and after the space.
What was happening is that I was not specifying the space correctly by
saying substring-before($str, ' ') I see now I need to use
substring-before($str, '&space;')

 <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,'&space;')}">
          <xsl:value-of select="substring-before($str,'&space;')"/></a>
              </td>
       <td width="200"><a href="{substring-after($str,'&space;')}">
            <xsl:value-of select="substring-after($str,'&space;')"/></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