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

Re: text nodes

Subject: Re: text nodes
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 15 Apr 2004 11:55:38 +0100
xsl match text
<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

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.