Solved

XSL Loop and incrementing variable

Posted on 2007-03-29
6
6,973 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create animated movies for web page 18 124
ER Diagram 3 42
SQL query for highest sequence 4 64
XSL - substring between 2 commas 12 25
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

726 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