[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: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Mon, 4 Mar 2002 16:18:29 -0500
Re:  Counting nodes processed
[JAY SCHERER]

> 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?
>

Minor changes.  If you want to show the category names like that, you should
iterate over the category elements. Output the category name once for each
iteration.  You have to restrict the allowed topics further, to ones whose
parent category element is the current one.  Mike Kay will probably say this
is inefficient, but at least it is fairly clear and simple.  I leave the
real formatting to you (that is, I'm still using <br/> elements for quick
and dirty newlines  in an IE display).

Notice that the expression from the original version, that retrieved that
name of the parent category of a topic, has become part of the restriction
on the allowed topic nodes.  It's still the same path expression, though,
since it is still referring to the same elements, the parent categories.

=====================================
<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='doc/category'/>
</results>
</xsl:template>

<xsl:template match='category'>
 <xsl:variable name='category' select='@value'/>
 <xsl:value-of select='$category'/><br/>
 <xsl:apply-templates
      select='$allowed-elements[ancestor::category[1]/
            @value=$category]'/>
</xsl:template>

<xsl:template match='topic'>
        <xsl:value-of select='@value'/><br/>
</xsl:template>


</xsl:stylesheet>
==============================

Results:
===============================
<results>
  category1
  <br />
  topic1
  <br />
  topic2
  <br />
  topic3
  <br />
  category2
  <br />
  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.