Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Hopefully simple XPath question (http://www.velocityreviews.com/forums/t168207-hopefully-simple-xpath-question.html)

Jon Thackray 11-10-2004 11:18 PM

Hopefully simple XPath question
 
I'm trying to use XPath to enable me to number items within sections
in a paper. I have so far tried about ten things, all of which it
seemed to me should work, and none of which do. Essentially what I
want is a count of the number of sections preceding the section which
is (the unique section) ancestor of the current node. Functionally
this would be

#PrecedingSiblings(SectionAncestorOf(CurrentNode))

But XPath doesn't seem to allow me to express this . I've no doubt it
can, I just can't currently see how. Can somebody please enlighten me.

Joris Gillis 11-11-2004 06:56 PM

Re: Hopefully simple XPath question
 
Hi,

> Essentially what I want is a count of the number ofsections preceding the section which is (the uniquesection) ancestor of the current node.


In Xpath, it would be: count(preceding::section)

but, it is more advisable to use the xslt approach, viz. 'xsl:number'
so you should use something like: <xsl:number level="any" count="section"/>
for full details, see http://www.w3.org/TR/xslt.html#number

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum

Jon Thackray 11-11-2004 09:48 PM

Re: Hopefully simple XPath question
 
jgt@pobox.com (Jon Thackray) wrote in message news:<518891d6.0411101518.2c6ca258@posting.google. com>...
Snip

No answer required any more, I've figured it out.

Jeff Kish 11-12-2004 05:08 AM

Re: Hopefully simple XPath question
 
On 11 Nov 2004 13:48:55 -0800, jgt@pobox.com (Jon Thackray) wrote:

>jgt@pobox.com (Jon Thackray) wrote in message news:<518891d6.0411101518.2c6ca258@posting.google. com>...
>Snip
>
>No answer required any more, I've figured it out.

And the answer is... ?


Jeff Kish 11-12-2004 05:09 AM

Re: Hopefully simple XPath question
 
On Thu, 11 Nov 2004 18:56:29 GMT, "Joris Gillis" <roac@pandora.be> wrote:

>Hi,
>
>> Essentially what I want is a count of the number ofsections preceding the section which is (the uniquesection) ancestor of the current node.

>
>In Xpath, it would be: count(preceding::section)
>
>but, it is more advisable to use the xslt approach, viz. 'xsl:number'
>so you should use something like: <xsl:number level="any" count="section"/>
>for full details, see http://www.w3.org/TR/xslt.html#number
>
>regards,

Just out of curiosity, why is it more advisable? Just trying to learn here.
Thanks

Joris Gillis 11-12-2004 09:55 AM

Re: Hopefully simple XPath question
 
>> but, it is more advisable to use the xslt approach, viz. 'xsl:number'
> Just out of curiosity, why is it more advisable? Just trying to learn here.
> Thanks
>

Hi,

It was only my own humble opinion :) , I should have mentioned that...
Since xslt defines a (flexible) numbering system (with quite advanced features), I see no need to invent a similar function (bound to very complicated when mimicing some features of 'xsl:number') by using Xpath. So, I prefer 'xsl:number' just to keep my code neat, flexible, extensible and comprehensible.

You don't have to agree off course. I'm just learning too.

regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum

Jon Thackray 11-12-2004 07:29 PM

Re: Hopefully simple XPath question
 
"Joris Gillis" <roac@pandora.be> wrote in message news:<opshbdq2jiyf9v9r@news.pandora.be>...
> Hi,
>
> > Essentially what I want is a count of the number ofsections preceding the section which is (the uniquesection) ancestor of the current node.

>
> In Xpath, it would be: count(preceding::section)


That doesn't quite do it. I ended up with this

<xsl:value-of select="1+count(ancestor::SECTION/preceding-sibling::SECTION)"/>

> but, it is more advisable to use the xslt approach, viz. 'xsl:number'
> so you should use something like: <xsl:number level="any" count="section"/>
> for full details, see http://www.w3.org/TR/xslt.html#number


I'll look into that.

Joris Gillis 11-12-2004 07:35 PM

Re: Hopefully simple XPath question
 
>> In Xpath, it would be: count(preceding::section)
>
> That doesn't quite do it. I ended up with this
>
> <xsl:value-of select="1+count(ancestor::SECTION/preceding-sibling::SECTION)"/>


That's strange, I would have sworn that "count(ancestor::SECTION/preceding-sibling::SECTION)" gave the same result as "count(preceding::section)" in your xml (or what I understood of it).
The '+1' change is logic off course.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum

Jon Thackray 11-13-2004 09:33 AM

Re: Hopefully simple XPath question
 
"Joris Gillis" <roac@pandora.be> wrote in message news:<opshc973seyf9v9r@news.pandora.be>...
> >> In Xpath, it would be: count(preceding::section)

> >
> > That doesn't quite do it. I ended up with this
> >
> > <xsl:value-of select="1+count(ancestor::SECTION/preceding-sibling::SECTION)"/>

>
> That's strange, I would have sworn that "count(ancestor::SECTION/preceding-sibling::SECTION)" gave the same result as "count(preceding::section)" in your xml (or what I understood of it).


It went wrong in the second CHAPTER. Given document structure below,
1+count(preceding::SECTION) gave

CHAPTER
SECTION Items numbered 1.1.x
SECTION Items numbered 1.2.x
SECTION Items numbered 1.3.x
CHAPTER
SECTION Items numbered 2.4.x

Where I wanted

CHAPTER
SECTION Items numbered 1.1.x
SECTION Items numbered 1.2.x
SECTION Items numbered 1.3.x
CHAPTER
SECTION Items numbered 2.1.x

> The '+1' change is logic off course.


Just making it 1 based rather then 0 based

Joris Gillis 11-13-2004 10:59 AM

Re: Hopefully simple XPath question
 
> I wanted
>
> CHAPTER
> SECTION Items numbered 1.1.x
> SECTION Items numbered 1.2.x
> SECTION Items numbered 1.3.x
> CHAPTER
> SECTION Items numbered 2.1.x


OK, I see.

with 'xsl:number', it would be something like:

<xsl:number level="any" count="CHAPTER"/><xsl:text>.</xsl:text>
<xsl:number level="any" from="CHAPTER" count="SECTION"/>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum


All times are GMT. The time now is 09:14 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.