Re: [xsl] Another tokenize() question

Subject: Re: [xsl] Another tokenize() question
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 10 Aug 2004 17:38:33 +0100
> I'm sure this has been asked before, but how does one tokenize 
> yet apply-templates within the thing you are tokenizing?

well tokenize needs a string as its input so once you tokenize any
element nodes in the input are gone as is usual in xslt the string value
of an element is its character data.

If teh templates you want to apply just produce character data (rather
than elements) and you can tokenize after they have been applied
then you can do

<xsl:template match="l">
 <xsl:variable name="x">
   <xsl:apply-templates/>
 </xsl:variable>
 <l><xsl:for-each select="tokenize(.,'\s+')[string(.)]">
...

so if l has a child element <foo/). that needs expanding to "a b c" and
hence tokenized as "a" "b" "c" this is all you need, but i suspect this
isn't what you need in which case you don't want tokenize you want
analyze-string (which I was going to suggest anyway once you mentioned
needing to get back your original lines.

tokenize forces its input to be a string and throws away all information
about the separators that appeared that might not be what you want.

so ...

<xsl:template match="l">
 <l>
  <xsl:apply-templates/>
 </l>
</xsl:template>

<xsl:template match="l/text()"> <!-- or l//text() according to taste-->
 <xsl:analyse-string regexp="\w+" select=".">
   <xsl:matching-substring><w><xsl:value-of select="."/></w></xsl:matching-substring>
   <xsl:non-matching-substring><xsl:value-of select="."/></xsl:non-matching-substring>
 </xsl:analyse-string>
</xsl:template>

Now if you do it this way you don'tjust get a list of w elements one for
each word you get them in situ, and around them you get your non-word
characters and anything that came from the apply-templates in the
template for l.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread