Solved

XSL Loop and incrementing variable

Posted on 2007-03-29
6
6,966 Views
Last Modified: 2013-12-12
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:


<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:


<?/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:


<?/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
0
Comment
Question by:ste_89
  • 3
  • 2
6 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18814821
try
<?/PO_DATA/LINE_ATTACHMENTS/TEXT[position()=last()]?>
0
 

Author Comment

by:ste_89
ID: 18814837
It just returns the last value when I try that (Telephone Number=6955_3<)

what I would like to do is display each one. Thanks.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18814885
In XSLT I would do something like this

<xsl:for-each select="/PO_DATA/LINE_ATTACHMENTS/TEXT"/>
...

but I don't know how to do that in the Oracle syntax

cheers

Geert
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:ste_89
ID: 18815042
Thanks Geert,

I found this by debugging an Oracle document. I've got to try and figure out how to get it into the RTF doc that XML publisher uses. Failing that, I will have to just modifiy the XSL that template builder produces.
Can you see what's going on here?

Cheers,


- <xsl:for-each select="$LINE_LONG_ATTACHMENTS_ROOT_OBJ">
- <xsl:if test="$lineID = .">
  <xsl:variable name="line" select="position()" />
  <xsl:value-of select="../TEXT[$line]" />
  <fo:block />
  </xsl:if>
  </xsl:for-each>
0
 
LVL 12

Accepted Solution

by:
jkmyoung earned 250 total points
ID: 18823999
If you could show where the variables $line, and $LINE_LONG_ATTACHMENTS_ROOT_OBJ, and $lineID are declared it would help.

Suggestion:
change this line from:
<xsl:value-of select="../TEXT[$line]" />

to:
<xsl:for-each select="../TEXT">
<xsl:value-of select="."/>
</xsl:for-each>
0
 

Author Comment

by:ste_89
ID: 18836115
Thanks jkmyoung....it did the trick.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now