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

Re: xsl:for-each within an element?

Subject: Re: xsl:for-each within an element?
From: "Dan Machak" <machak@xxxxxxxxxxxx>
Date: Fri, 27 Aug 1999 10:12:17 -0700
xsl for each string list
On Aug 27,  9:00am, Rich Gazan wrote:
> Subject: xsl:for-each within an element?
> I have a whole mess of semicolon-delimited input that looks like this:
>
> <field>thing1; thing2;...thingn</field>
>
> I'm trying to transform it to this:
>
> <field>thing1</field>
> <field>thing2</field>
> etc...

I had the same problem with parsing a list of indeterminate length, and the
solution was to use a call-template in a recursive fashion. Here is a
stylesheet that should work (I ran this with XT19990813)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:template match="/">
  <result>
  <xsl:call-template name="recurse">
    <xsl:with-param name="parse-string">
      thing1; thing2; thing3; thing4
    </xsl:with-param>
  </xsl:call-template>
  </result>
</xsl:template>

<xsl:template name="recurse">
  <xsl:param name="parse-string"></xsl:param>
  <xsl:if test="not($parse-string='')">
    <field>
      <xsl:choose>
      <xsl:when test="contains($parse-string, ';')">
        <xsl:value-of select="substring-before($parse-string, ';')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$parse-string"/>
      </xsl:otherwise>
      </xsl:choose>
    </field>
    <xsl:call-template name="recurse">
      <xsl:with-param name="parse-string">
        <xsl:value-of select="substring-after($parse-string, ';')"/>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

>
> Rich Gazan
>

>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>-- End of excerpt from Rich Gazan

Dan Machak


-- 
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<> Dan Machak                    <>  machak@xxxxxxxxxxxx  <>
<> MS T27A-1                     <>  650-604-2388 (VOICE) <>
<> NASA Ames Research Center     <>  650-604-3957 (FAX)   <>
<> Moffett Field, CA 94035-1000  <>                       <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>


 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.