Re: [xsl] text nodes

Subject: Re: [xsl] text nodes
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 15 Apr 2004 11:55:38 +0100
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">



<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="b"/>


<xsl:template match="a|c">
<xsl:copy>
<xsl:variable name="l">
<xsl:apply-templates mode="n" select="node()[1]"/>
</xsl:variable>
<xsl:variable name="ll" select="number(substring($l,1,4))"/>
<xsl:if test="$ll=$ll">
<xsl:attribute name="l"><xsl:value-of select="number(substring($l,1,4))"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates mode="a" select="node()[1]"/>
<xsl:apply-templates select="node()[position()&gt;1]"/>
</xsl:copy>
</xsl:template>



<xsl:template match="*" mode="n">
<xsl:apply-templates mode="n" select="node()[1]"/>
</xsl:template>


<xsl:template match="*" mode="a">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="a" select="node()[1]"/>
<xsl:apply-templates select="node()[position()&gt;1]"/>
</xsl:copy>
</xsl:template>

<xsl:template match="text()" mode="a">
<xsl:choose>
<xsl:when test="following-sibling::*[1][self::b]"/>
<xsl:when test="translate(substring(.,1,4),'0123456789','')=''">
 <xsl:value-of select="substring(.,5)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>





<root>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<c><a>This is a line</a></c>
<a>5<b>000</b> line <d>five</d></a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<c><a>10<b>00</b> line ten</a></c>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line and lots missing</a>
<a><d>1000 This is</d> also a line</a>
<a><d>This </d>is a line</a>
<a>3523 This is a later line</a>
<a>This is a line</a>
</root>



$ saxon lines.xml lines.xsl
<?xml version="1.0" encoding="utf-8"?><root>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<c><a>This is a line</a></c>
<a l="5"> line <d>five</d></a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<c l="10"><a> line ten</a></c>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line</a>
<a>This is a line and lots missing</a>
<a l="1000"><d> This is</d> also a line</a>
<a><d>This </d>is a line</a>
<a l="3523"> This is a later line</a>
<a>This is a line</a>
</root>




-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread