|
|
 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

March 29th, 2007, 05:27 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
XSL Loop and incrementing a variable
We are using Oracle XML Publisher to generate PDF formatted Purchase Order Reports. We have tried Oracle Support, but haven't got anywhere, hence trying here...
As part of this work, we have hit a problem.
Part of the XML contains the following data:
Code:
<PO_DATA>
<LINE_ATTACHMENTS>
<TEXT> Telephone Number=6955_1 </TEXT>
<ID>765923</ID>
<TEXT> Telephone Number=6955_2 </TEXT>
<ID>765924</ID>
<TEXT>Telephone Number=6955_3</TEXT>
<ID>765925</ID>
</LINE_ATTACHMENTS>
</PO_DATA>
What we want to do is to loop through the values in the <LINE_ATTACHMENTS> tag, and output the Text Value.
If we try the following snippet:
Code:
<?/PO_DATA/LINE_ATTACHMENTS/TEXT[3]?>
Then when we view the output, the XSL will always display the value of the 3rd iteration of the <TEXT> tag.
That's okay - but we don't want to hard code the [3] value. We want instead for the number there to be the row count that is currently being used.
We have tried this:
Code:
<?/PO_DATA/LINE_ATTACHMENTS/TEXT["row:position()]?>
But a long error message was returned.
Basically, we want to increment a variable for each loop through the data, and output the value of that incremented variable in the square brackets as detailed above.
Can this be done?
Thanks
Jim
|

March 29th, 2007, 06:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 Posts
|
|
Your terminology is wrong which makes it difficult to answer, you can't iterate/loop in XSLT. Do you want to show the last TEXT element in LINE_ATTACHMENTS? In that case PO_DATA/LINE_ATTACHMENTS/TEXT[last()] should do. Otherwise please explain what you mean by "row count that is currently being used".
--
Joe ( Microsoft MVP - XML)
|

March 29th, 2007, 06:51 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry for my unclear explanation.
What is happening is that we are using an XML document which contains the raw data for the PO (PO header, order lines etc.).
Oracle XML Publisher uses a Word Template to create a report formatted as a PDF document. The output of this is an xsl file which formats the XML data correctly.
As part of that, there is a Group By statement which loops through the po order lines to show the line level information held of the Purchase Order.
So when I said "row count that is currently being used" what I should have said is to return the number of the row being looped through via the group statement.
Last() would be okay - but then using the XML snipped I pasted here, it would only ever return the last value, and then repeats it three times.
Thanks
Jim
|

March 29th, 2007, 07:12 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 Posts
|
|
Sounds like you need the position() function, can you show more of XSL?
--
Joe ( Microsoft MVP - XML)
|

March 29th, 2007, 07:28 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe,
this is a snippet of the XSL - tried position() but it only returns the first of the text values, and repeats it 3 times:
Code:
- <fo:block xdofo:xliff-note="TEXT" xdofo:use-attribute-sets="b_42 b_1">
- <fo:inline xdofo:use-attribute-sets="i_27">
<xsl:value-of select="/PO_DATA/LINE_ATTACHMENTS/TEXT[position()]" xdofo:field-name="/PO_DATA/LINE_ATTACHMENTS/TEXT[position()]" />
</fo:inline>
</fo:block>
It looks close - but not close enough!
Thanks
Jim
|

March 29th, 2007, 04:52 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Hi,
You say:
What we want to do is to loop through the values in the <LINE_ATTACHMENTS> tag, and output the Text Value.
but your code asked for the position:
<xsl:value-of select="/PO_DATA/LINE_ATTACHMENTS/TEXT[position()]"
if you want the values in the <LINE_ATTACHMENTS> tag, just use:
<xsl:value-of select="/PO_DATA/LINE_ATTACHMENTS/TEXT"/>
|

March 29th, 2007, 05:10 PM
|
 |
Wrox Author
Points: 12,735, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
position() determines the position of the context item in the list of items currently being processed. Within [], the context item refers to the item being tested, and the "list of items being processed" is the set of nodes you are filtering. Looking at it another way, using an integer value $X within square brackets [$X] is short for [position()=$X], so [position()] is short for [position()=position()] which matches every node. You need to bind a variable to the value of position() outside the predicate, and then use the variable within the square brackets.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

March 30th, 2007, 11:01 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the replies,
the last one made sense - so, I tried this in XML Publisher:
<xsl:variable name="line" select="position()" />
<?/PO_DATA/LINE_ATTACHMENTS/TEXT[$line]?>
Still, it only ever displays the first value of the text tag from line_attachments, and repeats it 3 times.
When I look at the resulting xsl document that XML publisher creates, the variable declaration is right at the top of the xsl document:
<xsl:variable xdofo:ctx="8" name="line" select="position()" />
while the part referencing line_attachments is much further down:
<xsl:value-of select="/PO_DATA/LINE_ATTACHMENTS/TEXT[$line]" xdofo:field-name="/PO_DATA/LINE_ATTACHMENTS/TEXT[$line]" />
I'm not sure where to go from here. I have asked Oracle support for advice, but they haven't advised!
Sorry if I'm not making a lot of sense here.
Thanks
Jim
|

March 30th, 2007, 11:41 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Maybe I am missing something...why are you asking for the position()?
I thought you wanted all the values (i.e. "What we want to do is to
loop through the values in the <LINE_ATTACHMENTS> tag, and output the Text Value."
Is this your intension?
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |