« DVD Backup With BackupEdgeComments in XML files »

Loops In XSL

03/03/05

Permalink 09:40:39 am, by admin Email , 293 words   English (US)
Categories: XSL-FO

Loops In XSL

1. Multiple looping within a report. Example: multiple UPS tracking numbers
to print in the footer of an invoice after detail lines have looped.

Loops are accomplished with xsl:apply-templates statements.

At the point in the document that you want the loop, insert an xsl:apply-templates tag with the select attribute set to the node that you want to loop on.

For example if you have tracking numbers in //report/tracking elements then use:

lt;xsl:apply-templates select="tracking" />

At the end of the document you'll want to define a template to render the tracking numbers. For example:

<xsl:template match="//report/tracking" >
<fo:block><xsl:value-of select="@number" /></fo:block>
</xsl:template>

Here's what the xml might look like:

<report>
<tracking number="123" />
<tracking number="456" />
<tracking number="789" />
</report>

So for each loop, create a template that renders the looped item and add an apply-templates element at the point where you want the template inserted.

There is also ans xsl:for-each looping construct. It works inline without the need for an additional template. with the example data above we could do:

<xsl:for-each select="//report/tracking">
<fo:block><xsl:value-of select="@number" /></fo:block>
</xsl:for-each>

You can have as many loops as you want.

2. Sub loops within loops. Example: each line item on an invoice could have
multiple lot numbers that need to be printed with everything that's
associated with those lots (Country of Origin, Date of Mfg, Manufacturer...)

Loops as describe above can be nested. For-each element can be nested inside of each other. An xsl-template can contain calls to xsl:apply-templates.

July 2010
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Reliable Penguin offers Linux Server Migrations, Systems Administration & Programming. Visit our main website at:

http://www.reliablepenguin.com

Search

Bookmark and Share

XML Feeds

blog tool