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