[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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 >stylesheet, >[snip] >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 anyway. Try this: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:variable name="NL" select="'
'"/> <xsl:template match="CHARACTER_ID"> <xsl:value-of select="."/> <xsl:value-of select="$NL"/> </xsl:template> <!-- throw away all text nodes --> <xsl:template match="text()" /> </xsl:stylesheet> 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. Regards 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|