[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: FW: XSL to split a concatenated XML string

Subject: RE: FW: XSL to split a concatenated XML string
From: "Rochak Palta" <rochak.palta@xxxxxxxxxxxxxx>
Date: Tue, 14 Mar 2006 17:46:13 +0530
split a string to tables
I applied the following XSL on your sample XML 

<table>
	<tr>
		<td>
			<xsl:text>STAND NUMBER</xsl:text>
		</td>
		<td>
			<xsl:text>STAND ADDRESS</xsl:text>
		</td>
	</tr>
	<xsl:for-each select="/optionList1/option">
		<xsl:variable name="str" select="."/>
		<tr>
			<td>
				<xsl:value-of
select="substring-before($str,'  ')"/>
			</td>
			<td>
				<xsl:value-of
select="substring-after($str,'  ')"/>
			</td>
		</tr>
	</xsl:for-each>
</table>



and it gave the following output:

STAND NUMBER 		    STAND ADDRESS 
T51000000000000000000000000 NONE,. 
T51000000000010000000000000 31 VAN STRAAT,. 
T51000000000020000000000000 29 VAN STRAAT,. 
T51000000000030000000000000 36 BECKERWEG,. 
T51000000000040000000000000 34 BECKERWEG,.

Does this solve your purpose?

Thanks

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

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:  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:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.