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

Re: Counting nodes processed

Subject: Re: Counting nodes processed
From: Jörg Heinicke <joerg.heinicke@xxxxxx>
Date: Mon, 4 Mar 2002 21:45:28 +0100
Re:  Counting nodes processed
Hello Jay,

I thought I sent a message a few hours ago, but I can't see it ;-)

Again the old version - without the bug:

<xsl:template match="root">
<xsl:apply-templates select="category"/>
</xsl:template>

<xsl:template match="category">
<xsl:value-of select="@value"/>
<xsl:text>&#10;</xsl:text>
<xsl:apply-templates select="topic"/>
</xsl:template>

<xsl:template match="topic">
<xsl:text>    </xsl:text>
<xsl:value-of select="@value"/>
<xsl:text>&#10;</xsl:text>
</xsl:template>

the new one:

change <xsl:apply-templates select="topic"/> to <xsl:apply-templates
select="topic[count(preceding::topic) &lt; 5]"/>

Joerg

----- Original Message -----
From: "JAY SCHERER" <jay.scherer@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, March 04, 2002 9:11 PM
Subject: RE:  Counting nodes processed


> This works fine except that I really only want to print the category 1
time, not each line.  In the previous solution I was able to test on the
position in the topic to eliminate the category header when not the 1st
time.  Any hints?
>
> jay
>
> -----Original Message-----
> From: Thomas B. Passin [mailto:tpassin@xxxxxxxxxxxx]
> Sent: Monday, March 04, 2002 11:02 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  Counting nodes processed
>
>
> [JAY SCHERER]
>
> > I've got a need to limit the amount of ouput generated in a translation.
> Assume the following xml
> >
> > <category value="category1">
> >   <topic value="topic1"/>
> >   <topic value="topic2"/>
> >   <topic value="topic3"/>
> > </category>
> > <category value="category2">
> >   <topic value="topic1"/>
> >   <topic value="topic2"/>
> >   <topic value="topic3"/>
> > </category>
> >
> > How would I limit my total number of topics output to say 4 topics?
This
> is straight forward in code, but not sure how to do it xsl?  Basically the
> output would be topic1,2 and 3 from category1 and topic 1 from category 2
> >
>
> cutlass <cutlass@xxxxxxxxxxx> suggested using position(), but that may not
> work because position() depends on the context of the current node, which
> can vary depending on how you refer to it.  It is easy to get unexpected
> results using position().
>
> Here is a different approach.  You first select just those topics you want
> to use.  If you want to output just four topics, you can select those
topics
> where the count of  all preceding topic elements  is less than 4.  This
will
> work unambiguously.
>
> Here's what it might look like:
>
> ====================================
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:variable name='allowed-elements'
> select='/doc/category/topic[count(preceding::topic)&lt;4]'/>
>
> <xsl:template match="/">
> <results>
>  <xsl:apply-templates select='$allowed-elements'/>
> </results>
> </xsl:template>
>
> <xsl:template match='topic'>
>  <xsl:value-of select='ancestor::category[1]/@value'/>-- <xsl:value-of
> select='@value'/><br/>
> </xsl:template>
>
> </xsl:stylesheet>
> ================================
>
> Here is the result (the <br/> is there only to give an artificial line
feed
> for visual formatting in Internet Explorer):
>
> ===============================
> <results>
>   category1-- topic1
>   <br />
>   category1-- topic2
>   <br />
>   category1-- topic3
>   <br />
>   category2-- topic1
>   <br />
>   </results>
> ==================================
>
> Cheers,
>
> Tom P



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


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.