You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Dane Foster <df...@equitytg.com> on 2000/11/16 19:07:02 UTC

Help with XPath

I'm having a bit of trouble coming up with the XPath/XSLT expression to express an algorithm.

<!--This is an example XML Fragment that my algorithm needs to work on-->
<parent-node type="generated">
    <child-node id="first-child" number-of-pages="10">
 <![CDATA[Text of page would go here]]>
    </child-node>
    <child-node id="second-child" number-of-pages="5">
 <![CDATA[Text of page would go here]]>
    </child-node>
    <child-node id="third-child" number-of-pages="20">
 <![CDATA[Text of page goes here]]>
    </child-node>
</parent-node>

<!--This is the output fragment that my algorithm should yield-->
           Table of Contents
first child.................................1
second child................................11
third child.................................16

*The "...." are not really part of the output.  They are simply for formatting and clarity

The purpose of the algorithm is to find out what page the 'CDATA' section of each 'child-node' would start on,
assuming that each CDATA section would begin on a new page.  This can be expressed as the following algorithm (in psuedo code):
- When the current 'child-node' is being processed
- For every 'child-node' before the current 'child-node' get the value of the 'number-of-pages' attribute
- Sum the values then add 1
- The value of the previous step is the page number that the 'CDATA' section of the current 'child-node' will start on ...

... Therefore if there were a forth-child element it would print,
fourth child............................. 36 (because 20 + 5 + 10 + 1 = 36)


The XSLT/XPath construct that I currently have looks like this (pretend the spacing, carriage returns, and tabs are being magically handled): 

<xsl:template match="parent-node[@type='generated']">
  Table of Contents

<xsl:for-each select="child-node">
 <xsl:value-of select="@id"/>..............<xsl:number value="sum(previous-siblings[attribute::pageCount)"/><!-- point of interest (POC)-->
</xsl:for-each>
</xsl:template>


I've tried all sorts of different expressions at POC.  The one you see now is just the latest.  Any help would be greatly appreciated.