|
Subject: Re: [xsl] Breaking a string into repeated elements From: Bryan Schnabel <bryan.schnabel@xxxxxxxxxxxxx> Date: Fri, 7 Jun 2002 14:37:56 -0700 (PDT) |
This kind of problem is pretty easy to find in the
archives. Once you get past the variety of possible
delimiters, it's pretty straight-forward.
This is one way:
<xsl:template match="ListOfItems">
<xsl:variable name="SpaceOrCommaOrBoth"
select="normalize-space(translate(text(),',',' '))"/>
<ListofItems>
<xsl:call-template name="Chop">
<xsl:with-param name="SpaceOrCommaOrBoth"
select="$SpaceOrCommaOrBoth"/>
</xsl:call-template>
</ListofItems>
</xsl:template>
<xsl:template name="Chop">
<xsl:param name="SpaceOrCommaOrBoth"/>
<xsl:choose>
<xsl:when test="contains($SpaceOrCommaOrBoth,' ')">
<xsl:call-template name="MakeItem">
<xsl:with-param name="ItemStff"
select="substring-before($SpaceOrCommaOrBoth,' ')"/>
</xsl:call-template>
<xsl:call-template name="Chop">
<xsl:with-param name="SpaceOrCommaOrBoth"
select="substring-after($SpaceOrCommaOrBoth,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="MakeItem">
<xsl:with-param name="ItemStff"
select="$SpaceOrCommaOrBoth"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="MakeItem">
<xsl:param name="ItemStff"/>
<item>
<xsl:value-of select="$ItemStff"/>
</item>
</xsl:template>
Bryan
--- jon budar-danoff <jbudardanoff@xxxxxxxxx> wrote:
> The construct in question looks like this:
>
> <ListOfItems>10, 20, 30, 31</ListOfItems>
>
> and I want to make it look like this:
>
> <ListOfItems howMany="4">
> <Item>10</Item>
> <Item>20</Item>
> <Item>30</Item>
> <Item>31</Item>
> </ListOfItems>
>
> Note that the existing <ListOfItems> may be
> delimited by either spaces,
> commas, or commas and spaces.
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Breaking a string into repeat, jon budar-danoff | Thread | [xsl] Re: Breaking a string into re, Dimitre Novatchev |
| RE: [xsl] keys vs. parameters, David N Bertoni/Camb | Date | Re: [xsl] keys vs. parameters, David Carlisle |
| Month |