xsl-list
[Top] [All Lists]

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

2006-03-14 05:31:03
Does actually.
Thanks
Simpler too 

-----Original Message-----
From: Rochak Palta [mailto:rochak(_dot_)palta(_at_)baypackets(_dot_)com] 
Sent: 14 March 2006 02:16 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] FW: XSL to split a concatenated XML string

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(_dot_)Cave(_at_)softwareag(_dot_)com]
Sent: Tuesday, March 14, 2006 5:22 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] 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(_dot_)Cave(_at_)softwareag(_dot_)com]
Sent: 14 March 2006 01:38 PM
To: Luke Stedman
Cc: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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(_dot_)stedman(_at_)gmail(_dot_)com]
Sent: 14 March 2006 01:28 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com; Cave, Neil;
neil(_dot_)cave(_at_)lists(_dot_)mulberrytech(_dot_)com
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(_dot_)Cave(_at_)softwareag(_dot_)com> 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
        
        
        
        
        
--~------------------------------------------------------------------
        XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
<http://www.mulberrytech.com/xsl/xsl-list> 
        To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
        or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com> >
        --~--
        
        



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--