RE: [xsl] New to XSL

Subject: RE: [xsl] New to XSL
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 21 Dec 2005 10:37:40 -0000
Try to choose a subject line that relates to your problem: at least half the
questions on this list are from people new to XSL.

Yes, it is possible. Like many things, it is much easier in XSLT 2.0 than in
XSLT 1.0. 

(I'm not sure what part the sep attribute plays in your problem, so I'm
ignoring it)

In 2.0, you can do

<xsl:for-each select="tokenize(textarea, '\s+')">
  <datum>
    <xsl:value-of select="."/>
  </datum>
</xsl:for-each>

(If the whitespace in your example output is significant, you'll need to add
it.)

In 1.0 you need to write a recursive named template. This reads and
processes the first item in the list using substring-before($input, ' '); it
then calls itself to process the remaining items in the list, identified
using substring-after($input, ' '). This takes a little bit of getting used
to at first if you don't have a background in functional programming. The
easiest way to get started might be to download the str:tokenize template
from www.exslt.org (which simply does what I described above) and integrate
it into your code.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Richard Zhang [mailto:richard_zhang@xxxxxxxxxx] 
> Sent: 20 December 2005 16:21
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] New to XSL
> 
> Hi,
> 
> I am new to XSLT and want to do the following but do not know 
> if it is 
> possible or not. Any help or references to sources would be greatly 
> appreciated.
> 
> I have an XML file with the following element:
> 
> <textarea sep=" &#x000A; &#x000D:"
>   10 20 30 40 50
> </textarea>
> 
> And I would like to be able to transform it into:
> 
> <datum>
>   10
> </datum>
> <datum>
>   20
> </datum>
> <datum>
>   30
> </datum>
> <datum>
>   40
> </datum>
> <datum>
>   50
> </datum>
> 
> Is this possible with XSLT?
> 
> Thank you in advance for any help.
> 
> Richard.

Current Thread