Subject: Re: [xsl] Applying Templates to a Substring From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 22 Oct 2004 00:32:44 +0300 |
If I have a <li> node like this:
<ol> <li>1) This is the <b>first</b> item.</li> <li>2) This is the 2<sup>nd</sup> item.</li> </ol>
and I want the output to be:
<ol> <li>This is the <b>first</b> item.</li> <li>This is the 2<sup>nd</sup> item.</li> </ol>
However I'm not aware of how you can apply-templates to a substring.
The only way I can get the proper substring I need that I know of is:
<xsl:value-of select="substring-after(.,')')"/>
T:\ftemp>type joe.xml <ol> <li>1) This is the <b>first</b> item.</li> <li>2) This is the 2<sup>nd</sup> item.</li> <li>1) This is the <b>1) first</b>1) item.</li> <li>2) This is the 2<sup>nd</sup> item.</li> <li><b>3) </b>Third</li> </ol> T:\ftemp>type joe1.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="li//text()[1]"> <xsl:choose> <xsl:when test="contains(.,') ')"> <xsl:value-of select="substring-after(.,') ')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
</xsl:stylesheet> T:\ftemp>saxon joe.xml joe1.xsl <?xml version="1.0" encoding="utf-8"?><ol> <li>This is the <b>first</b> item.</li> <li>This is the 2<sup>nd</sup> item.</li> <li>This is the <b>first</b>1) item.</li> <li>This is the 2<sup>nd</sup> item.</li> <li><b/>Third</li> </ol> T:\ftemp>type joe2.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="li//text()[1]"> <xsl:choose> <xsl:when test="ancestor-or-self::node()[not(descendant-or-self::li)]/ preceding-sibling::node() or not(contains(.,') '))"> <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> <xsl:value-of select="substring-after(.,') ')"/> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
</xsl:stylesheet> T:\ftemp>saxon joe.xml joe2.xsl <?xml version="1.0" encoding="utf-8"?><ol> <li>This is the <b>first</b> item.</li> <li>This is the 2<sup>nd</sup> item.</li> <li>This is the <b>1) first</b>1) item.</li> <li>This is the 2<sup>nd</sup> item.</li> <li><b/>Third</li> </ol> T:\ftemp>
-- World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Applying Templates to a Subst, Joe Heidenreich | Thread | [xsl] how to store node in variable, John |
Re: [xsl] union vs. "or" vs. contai, Bruce D'Arcus | Date | Re: [xsl] how to store node in vari, Wendell Piez |
Month |