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

Re: pattern matching in xslt

Subject: Re: pattern matching in xslt
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Tue, 23 Apr 2002 13:56:01 -0700
xslt recursive pattern matching
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 13:32 23/4/02, David Nelson wrote:
>I would sincerely apprec. any help you might offer.  What I need to do is
>tokenize a node value into chunks, filter the trash and return in the xml,
>the new clean string. I'm a newbie with xslt and am having a tough time
>deciphering how to accomplish this.

This (string processing) is not XSLT's strong suit, which is probably why 
you're having trouble finding the cookbook solution.

There are two ways to approach it.  One, which is probably more efficient, 
is to use extension functions; you can just access the various Java string 
functions directly.

The "pure" way to do it is to use a recursive function; something like

<xsl:template match="description">
   <xsl:call-template name="process-text">
     <xsl:with-param name="string" select="."/>
   </xsl:call-template>
</xsl:template>

<xsl:template name="process-text">
   <xsl:param name="string" select="''"/>
   <xsl:choose>
     <xsl:when test="not(contains($string, '.. '))">
       <xsl:value-of select="$string"/>
     </xsl:when>
     <xsl:otherwise>
       <xsl:value-of
         select="substring-before($string, '.. ')"/>
       <xsl:call-template name="process-text">
         <xsl:with-param name="string"
           select="substring-after($string, '.. ')"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

~Chris
- -- 
Christopher R. Maden, Principal Consultant, crism consulting
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA
-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.8

iQA/AwUBPMXKYaxS+CWv7FjaEQJQOQCfVA0sWrqO0ZdVkbxLIwzFLuiHvewAoPaC
EwQ05fb7zzln0OwosWigNEO5
=m9AW
-----END PGP SIGNATURE-----


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.