M
Mark Bordner
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>
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>