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

Re: Another tokenize() question

Subject: Re: Another tokenize() question
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 10 Aug 2004 17:38:33 +0100
xsl tokenize
> 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

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.