Solved

XSL Loop and incrementing variable

Posted on 2007-03-29
6
6,975 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

707 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