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

Re: Count() elements in range

Subject: Re: Count() elements in range
From: "M. David Peterson" <conners_dad@xxxxxxx>
Date: Thu, 16 Oct 2003 03:58:13 -0700
number of elements in range
Chris,

After taking the time to read this over im a bit confused as to what node you are trying to get at to begin your count...

> count the number of <element> nodes in the tree starting from the
> last <element> or the last <element> whose following-sibling::element does
> not have a child <flag>.

Can you please clarify what it is exactly that you re looking for? In the following tree can you point out where you want to begin the count, which direction you want to go, and what nodes your do or dont want to include in the count?...


<?xml version="1.0" encoding="UTF-8" ?>
<root>
<!--start A series of 1 -->
<element number="A1">
<flag/>
</element>
<!-- start B series of 4 -->
<element number="B1">
<flag/>
</element>
<element  number="B2"/>
<element  number="B3"/>
<element  number="B4"/>
<!-- start C series of 2 -->
<element  number="C1">
<flag/>
</element>
<element  number="C2"/>
<!-- start D series of 3 -->
<element  number="D1">
<flag/>
</element>
<element  number="D2" />
<element  number="D3" />
</root>

You are right, it is just a simple XPath issue... but if you help me better understand what it is you want I can give a lot more help in writing the XPath.

Thanks!

M.


From: "M. David Peterson" <conners_dad@xxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re:  Count() elements in range
Date: Wed, 15 Oct 2003 21:05:10 -0600

Chris,

At first glance I noticed you have following-sibling wrapped in parentheses.
The only time you will use parentheses is when you are invoking a function.
In this case you are just searching for a particular node using a standard
XPath expression.


So, this...

<xsl:when test="(following-sibling::element[1][child::flag]) or
> (count(following-sibling::element) = 0)">

should read like this...

<xsl:when test="following-sibling::element[1][child::flag] |
count(following-sibling::element) = 0)">

Im rushing out the door and don't have time to look to see what other issues
you might have or what solutions would work best but if I get back and this
hasn't helped or someone else hasn't been able to help I will take another
look at it.


Best regards,

M.


----- Original Message ----- From: <Chris.Pearson@xxxxxxxxxxxx> To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, October 15, 2003 6:33 PM Subject: Count() elements in range


> I am wrestling with a problem related to counting a specific range of
> elements in a source document. I've tried searching the archives, but I
> was
> unable to locate any past discussions that appeared relevant.
>
>
> Problem: count the number of <element> nodes in the tree starting from the
> last <element> or the last <element> whose following-sibling::element does
> not have a child <flag>. I think my issue is simply a matter of XPath
> expressions, but my brain keeps trying differing versions of recursion
> with
> no luck.
>
>
> Source xml:
> <?xml version="1.0" encoding="UTF-8" ?>
> <root>
> <!--start A series of 1 -->
> <element number="A1">
> <flag/>
> </element>
> <!-- start B series of 4 -->
> <element number="B1">
> <flag/>
> </element>
> <element number="B2"/>
> <element number="B3"/>
> <element number="B4"/>
> <!-- start C series of 2 -->
> <element number="C1">
> <flag/>
> </element>
> <element number="C2"/>
> <!-- start D series of 3 -->
> <element number="D1">
> <flag/>
> </element>
> <element number="D2" />
> <element number="D3" />
> </root>
>
>
> Stylesheet so far:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="text" media-type="text/plain"/>
> <xsl:strip-space elements="*" />
>
> <xsl:template match="/root/element">
> <xsl:choose>
> <xsl:when test="(following-sibling::element[1][child::flag]) or
> (count(following-sibling::element) = 0)">
> <xsl:call-template name="countFlags">
> <xsl:with-param name="nodeList"
> select="preceding-sibling::element"
> />
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise />
> </xsl:choose>
> </xsl:template>
>
> <xsl:template name="countFlags">
> <xsl:param name="nodeList"/>
> <!-- do something here to count the preceding-sibling::element nodes up to
> the first <element> whose following-sibling::element does not have a
> <flag>
> child. -->
> </xsl:template>
> </xsl:stylesheet>
>
>
> Thanks in advance,
>
>
> Chris
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>


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


_________________________________________________________________
Add MSN 8 Internet Software to your current Internet access and enjoy patented spam control and more. Get two months FREE! http://join.msn.com/?page=dept/byoa



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.