|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:for-each within an element?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








