This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pattern matching in xslt



-----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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]