473,385 Members | 2,243 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,385 software developers and data experts.

Help with XPATH "position" of element

Hi All,
Given the following XML, I've been trying to figure out what XPATH
expression will give me the "position" of a <lineitem> within the
<shipto> that is its grandparent.

To give you an idea of what I'm trying to do...I'm transforming this
XML into XSL-FO; which I will process with FOP to produce a PDF file.
Each <shipto> element with the XML correlates to a new "section"
within the target PDF document. I need to know when I've reached the
last <lineitem> within a <shipto> so I can output some summary
information.

The way I'm approaching this in the XSLT stylesheet is

1. Within the template for <lineitem>, I can use
"count(../..//lineitem)" to give me the total number of <lineitem>'s
within this <shipto>. Then, I want to get the "position" of the
current <lineitem> within the current <shipto>, which I can them
compare against the total to see if this is the last <lineitem>.

I know the XPATH will be "count({something}) + 1", but I've just not
had any luck determining what "{something}" should be.

Obviously, there could be (and probably is :-) a better (or at least
more elegant) solution to this; but it seems like this will work.

Thanks in advance for any assistance.

Regards,
Mark

<?xml version="1.0" encoding="UTF-8"?>
<shipment_coo>
<shipto code="1">
<invoice id="1">
<lineitem id="1"/>
<lineitem id="2"/>
<lineitem id="3"/>
<lineitem id="4"/>
</invoice>
<invoice id="2">
<lineitem id="1"/>
<lineitem id="2"/>
<lineitem id="3"/>
<lineitem id="4"/>
</invoice>
<invoice id="3">
<lineitem id="1"/>
<lineitem id="2"/>
<lineitem id="3"/>
<lineitem id="4"/>
</invoice>
</shipto>
<shipto code="2">
<invoice id="4">
<lineitem id="1"/>
<lineitem id="2"/>
<lineitem id="3"/>
<lineitem id="4"/>
</invoice>
<invoice id="5">
<lineitem id="1"/>
<lineitem id="2"/>
<lineitem id="3"/>
<lineitem id="4"/>
</invoice>
</shipto>
</shipment_coo>
Jul 20 '05 #1
2 5139

"Mark Bordner" <ma***@trebax.com> wrote in message
news:27**************************@posting.google.c om...
Hi All,
Given the following XML, I've been trying to figure out what XPATH
expression will give me the "position" of a <lineitem> within the
<shipto> that is its grandparent.

To give you an idea of what I'm trying to do...I'm transforming this
XML into XSL-FO; which I will process with FOP to produce a PDF file.
Each <shipto> element with the XML correlates to a new "section"
within the target PDF document. I need to know when I've reached the
last <lineitem> within a <shipto> so I can output some summary
information.


Use:

not(following-sibling::lineitem) and not(../following-sibling::invoice)

When the current node is a "lineitem" the above XPath expression will
evaluate to true() only when this "lineitem" element is the last "grandson"
of its "grandfather".

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #2

Outstanding! I was thinking that there was a different way to look at
this problem. Thank you very much for the solution and the insight.

Dimitre Novatchev [MVP XML] wrote:
"Mark Bordner" <ma***@trebax.com> wrote in message
news:27**************************@posting.google.c om...
Hi All,
Given the following XML, I've been trying to figure out what XPATH
expression will give me the "position" of a <lineitem> within the
<shipto> that is its grandparent.

To give you an idea of what I'm trying to do...I'm transforming this
XML into XSL-FO; which I will process with FOP to produce a PDF file.
Each <shipto> element with the XML correlates to a new "section"
within the target PDF document. I need to know when I've reached the
last <lineitem> within a <shipto> so I can output some summary
information.

Use:

not(following-sibling::lineitem) and not(../following-sibling::invoice)

When the current node is a "lineitem" the above XPath expression will
evaluate to true() only when this "lineitem" element is the last "grandson"
of its "grandfather".

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html

Jul 20 '05 #3

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

Similar topics

1
by: nobody | last post by:
hi there! given <!ELEMENT a (#PCDATA | x)*> <!ELEMENT x (#PCDATA)> how can I find out if x is "embedded" at the beginning <a><x>xxx</x>aaa</a> or at the end <a>aaa<x>xxx</x></a> or in the...
2
by: Jessard | last post by:
Hi All, I am writing a .NET app that accesses an access View. The view has a table column called 'Position'. When i try and right an UpdateCommand string for this using this column I am...
4
by: Ghyslaine Crespe | last post by:
Hello, In my script, the line document.getElementById(id).style.background-position = "-200px -500px"; fails ! So, how can I change the background-position value ?
4
by: Guy | last post by:
Hi, I read an XML file to an XMLDocument and iterate through its nodes. How do I get the XPath position (index) of a certain element? For example If I on the second "b" node I want to get "2": ...
1
by: tschoepi | last post by:
Hi there, if I try to access a table named Position in an Access-Database via OleDbDataAdapter I get an error. If I rename the table to e.g. Positions it works. Any idea how to solve this...
2
by: petermichaux | last post by:
Hi, I tried the following and everything worked fine. element.style.position="relative"; Then I tried to make the CSS rule important and it didn't work. The positioning was all wrong in...
1
by: vunet.us | last post by:
Mozilla reported the fix to this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=167801. When input text field is located over div, the cursor cannot be seen unless special CSS properties are...
3
by: Ronald S. Cook | last post by:
Consider the following DataTable: FoodId FoodName FoodType 1 Apple Fruit 2 Pear Fruit 3 Corn Vegetable 4 ...
1
by: thomasv | last post by:
Hi, I want to convert the following XML (OpenOffice Calc file): <?xml version="1.0" encoding="UTF-8"?> <office:document-content ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.