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

Re: Parsing & splitting a string n times

Subject: Re: Parsing & splitting a string n times
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 24 May 2002 06:08:57 -0700 (PDT)
string n
>   I have the following problem. Could someone help, please?
>  
>   I have a string in the following format: 
>   
>    <add-attr attr-name="PHONENO">
>          <value type="string">value1,value2,valu3,......</value>
>     </add-attr>
> 
>    the number of values are not fixed & can vary every time.
> 
>     I need to split this string at the commas & put each value in a 
> separate value tag.
> 
>    like:
>      <add-attr attr-name="PHONENO">
>          <value type="string">value1</value>
>          <value type="string">value2</value>
>          <value type="string">value3</value>
>          .
>          .
>          .	
>     </add-attr>
> 
>    What i would like to know is, Are the concepts like arrays/lists 
> or loops handled in XSL?

Using FXSL one would write the following:

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:vendor="urn:schemas-microsoft-com:xslt" 
 exclude-result-prefixes="vendor"
 >
 
 <xsl:import href="strSplit-to-Words2.xsl"/>

   <xsl:output indent="yes" omit-xml-declaration="yes"/>
   
    <xsl:template match="/">
      <xsl:variable name="vRTFWords">
        <xsl:call-template name="str-split-to-words">
          <xsl:with-param name="pStr" select="/*/*"/>
          <xsl:with-param name="pDelimiters" 
                         select="', &#9;&#10;&#13;'"/>
        </xsl:call-template>
      </xsl:variable>
      
     <add-attr attr-name="PHONENO">
      <xsl:apply-templates select="vendor:node-set($vRTFWords)/word"/>
     </add-attr>
    </xsl:template>
    
    <xsl:template match="word">
      <value type="string">
        <xsl:copy-of select="node()"/>
      </value>
    </xsl:template>

</xsl:stylesheet>

When applied on the following source xml:

<add-attr attr-name="PHONENO">
  <value type="string">value1,value2,value3</value>
</add-attr>

this transformation produces the following result:

<add-attr attr-name="PHONENO">
  <value type="string">value1</value>
  <value type="string">value2</value>
  <value type="string">value3</value>
</add-attr>


Cheers,
Dimitre Novatchev.



__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.