473,379 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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.
Jul 20 '05 #1
9 1604
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
Jul 20 '05 #2
jg*@pobox.com (Jon Thackray) wrote in message news:<51**************************@posting.google. com>...
Snip

No answer required any more, I've figured it out.
Jul 20 '05 #3
On 11 Nov 2004 13:48:55 -0800, jg*@pobox.com (Jon Thackray) wrote:
jg*@pobox.com (Jon Thackray) wrote in message news:<51**************************@posting.google. com>...
Snip

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

And the answer is... ?

Jul 20 '05 #4
On Thu, 11 Nov 2004 18:56:29 GMT, "Joris Gillis" <ro**@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
Jul 20 '05 #5
>> 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
Jul 20 '05 #6
"Joris Gillis" <ro**@pandora.be> wrote in message news:<op**************@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.
Jul 20 '05 #7
>> 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
Jul 20 '05 #8
"Joris Gillis" <ro**@pandora.be> wrote in message news:<op**************@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
Jul 20 '05 #9
> 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
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joshua Beall | last post by:
Hi All, I have a task that should be very simple but I'm running into trouble. All I want to do is query a document using XPath, and save the resulting XML in a string. Here's that I am trying...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
6
by: Tommy | last post by:
For a XML fragment like below <ns0:BusCar_Request xmlns:ns0="http://BTSDG_SQL"> <ns0:sync> <ns0:after> <ns0:BusinessCards NameOnCard="NameOnCard_1" TitleOnCard="TitleOnCard_1" Quantity="10" />...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
6
by: Armel Asselin | last post by:
Hello, I'm searching for a simple command line tool to manipulate XML files. The idea would be commands such as that: xmanip-tool set /document/xpath/@name="value" remove //wrong-nodes add...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.