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

RE: Can XSLT be used to parse and "break up" a single

Subject: RE: Can XSLT be used to parse and "break up" a single XML Tag value?
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Wed, 23 Apr 2003 16:10:50 +0100
xsl parse tokens
Hi

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> John Svazic
> Sent: Wednesday, April 23, 2003 3:42 PM
> To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
> Subject:  Can XSLT be used to parse and "break up" a 
> single XML Tag value?
> 
> 
> Basically what I have is something like the following:
> 
> <field name="links">Project 
> Page=http://www.mycomp.com/project.htm;Feature
> Page=http://www.mycomp.com/feature.htm</field>
> 
> What I want to do is to break up each "section" (delimited with a
> semi-colon) and then break up each of these "sections" into 
> the display name and URL (delimited by the equals sign).  Is 
> there any way to do this in XSLT?  TIA.
> 

Try this:
 <xsl:template match="field">
  <xsl:call-template name="tokens"/>
 </xsl:template>
 
 <xsl:template name="tokens">
  <xsl:param name="str" select="string(.)"/>
  <xsl:param name="sep" select="' '"/>
  <xsl:choose>
   <xsl:when test="contains($str,';')">
   <xsl:call-template name="links">
    <xsl:with-param name="str" select="substring-before($str,';')"/>
   </xsl:call-template>
   <xsl:value-of select="$sep"/>
   <xsl:call-template name="tokens">
    <xsl:with-param name="str" select="substring-after($str,';')"/>
   </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
   <xsl:call-template name="links">
    <xsl:with-param name="str" select="$str"/>
   </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
 
 <xsl:template name="links">
  <xsl:param name="str" select="string(.)"/>
  <xsl:choose>
   <xsl:when test="contains($str,'=')">
   <a href="{substring-after($str,'=')}"><xsl:value-of
select="substring-before($str,'=')"/></a>
   </xsl:when>
   <xsl:otherwise>
   <a href="{$str}"><xsl:value-of select="$str"/></a>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>



 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.