Top Nav

Archive | 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.

0

Comments in XML files

How do you put comments in an XML file?

Comments are the same as in html – just do:

<!– my comment here –>

0

Image Sizes In XSL-FO

Here was the question:

And here was the answer:

This problem come down to image resolutiosn. Here’s an FO faq entry that talks about image resolution. I think this is where your problem is coming from:

http://xml.apache.org/fop/graphics.html#resolution

Here’s a link to the fo:external-graphic description in the spec:

http://www.w3.org/TR/xsl/slice6.html#fo_external-graphic

To attributes that look relevant are “scaling” and “scaling-method”.

0