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
Solved

XSL Loop and incrementing variable

Posted on 2007-03-29
6
6,971 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

792 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