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

Re: stylesheet vs egrep

Subject: Re: stylesheet vs egrep
From: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Fri, 25 Jan 2002 12:16:35 +0000
Re:  stylesheet vs egrep
On Fri, 25 Jan 2002 11:35:49 +0000, Ahmad J Reeves wrote:

>Hi there,
>I have xml files that contain 4 types of tags,
>direct,local,global and admin in varying numbers

>I need to get a list of all the character_id's, and then
>remove the duplicates and count them. With the following
>Is it my stylesheet thats lying, or my egrep ?
The stylesheet, because you are forgetting the built-in templates.
This means two things:
1. the default is to copy text nodes to the output: some of these are
numbers, hence the strange results.
2. you are doing much more work than is necessary, since most of your
templates are just visiting children, which is what the default does

Try this:
 <xsl:output method="text"/>

<xsl:variable name="NL" select="'&#xA;'"/> 

 <xsl:template match="CHARACTER_ID">
        <xsl:value-of select="."/>
        <xsl:value-of select="$NL"/>

<!-- throw away all text nodes -->
<xsl:template match="text()" />


The only reason for putting other templates in would be to avoid
traversing bits of the document where you know there are no
CHARACTER_ID nodes, which might make the transform a bit faster.
Unless the input document is huge this isn't likely to make much
difference, and of course it makes it more prone to bugs.

Trevor Nash
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@xxxxxxxxxxxxx

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


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.
First Name
Last Name
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.