p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 29th, 2007, 05:27 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old March 29th, 2007, 06:34 AM
joefawcett's Avatar
Wrox Author
Points: 8,994, Level: 40
Points: 8,994, Level: 40 Points: 8,994, Level: 40 Points: 8,994, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 Posts
Default

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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old March 29th, 2007, 06:51 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old March 29th, 2007, 07:12 AM
joefawcett's Avatar
Wrox Author
Points: 8,994, Level: 40
Points: 8,994, Level: 40 Points: 8,994, Level: 40 Points: 8,994, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 2,922
Thanks: 0
Thanked 13 Times in 12 Posts
Default

Sounds like you need the position() function, can you show more of XSL?

--

Joe (Microsoft MVP - XML)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old March 29th, 2007, 07:28 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old March 29th, 2007, 04:52 PM
Friend of Wrox
Points: 1,343, Level: 14
Points: 1,343, Level: 14 Points: 1,343, Level: 14 Points: 1,343, Level: 14
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bonekrusher
Default

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"/>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old March 29th, 2007, 05:10 PM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old March 30th, 2007, 11:01 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old March 30th, 2007, 11:41 AM
Friend of Wrox
Points: 1,343, Level: 14
Points: 1,343, Level: 14 Points: 1,343, Level: 14 Points: 1,343, Level: 14
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bonekrusher
Default

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Incrementing the variable value Swetha XSLT 2 April 28th, 2008 05:43 PM
Way to incrementing value of variable in xsl vikkiefd XSLT 14 March 12th, 2008 11:33 PM
For Loop Not incrementing donrafeal7 Javascript 1 October 24th, 2006 01:24 AM
incrementing javascript loop use i++ or ++i crmpicco Javascript How-To 4 May 11th, 2006 02:39 AM
incrementing value of a variable akibaMaila VB.NET 2002/2003 Basics 4 July 5th, 2005 01:04 PM



All times are GMT -4. The time now is 01:15 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc