morrell wrote:
Is there any chance you can check if a fo:block with an
id of "Tips" contains any data.
You mean - in a resulting tree fragment? I believe there
are ways to do that with EXSLT, but there doesn't seem to
be any need to, not in your case.
The problem I'm having is creating a fo:block then
for-each node within one part of the xml I'm testing if
scores match a particular high/Low then printing Tips.
If there are no tips printed I would like to write a
particular statements which says "No Tips"
Here's an example that should get you started:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<Scale id="1" min="2" max="4">Statement 1</Scale>
<Scale id="2" min="2.4" max="3.5">Statement 2</Scale>
<Scale id="3" min="3" max="5">Statement 3</Scale>
<Scale id="4" min="1" max="3">Statement 4</Scale>
<Scale id="5" min="1.5" max="4.2">Statement 5</Scale>
</data>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output
method="xml"
version="1.0"
encoding="UTF-8"/>
<xsl:param name="score" select="1"/>
<xsl:template match="/">
<xsl:apply-templates select="data"/>
</xsl:template>
<xsl:template match="data">
<xsl:variable
name="tips"
select="
Scale
[
($score>=@min) and
($score<=@max)
]
"/>
<block id="Tips">
<xsl:choose>
<xsl:when test="$tips">
<xsl:apply-templates select="$tips" mode="tips"/>
</xsl:when>
<xsl:otherwise>
No tips.
</xsl:otherwise>
</xsl:choose>
</block>
</xsl:template>
<xsl:template match="Scale" mode="tips">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
Hope that helps. Oh, and a hint - XSLT is a functional
language, not an imperative one. YMMV, but adjusting to
functional paradigm seems to lead to better results than
trying to fit XSLT into the Procrustean bed of imperative
programming. It's not that there's anything wrong with
imperative paradigm, it's just that XSLT was not designed
to be used that way.
--
roy axenov