Fo:Block can you check to see if a block contains any text by using the block id?

M

morrell

Hi all

Is there any chance you can check if a fo:block with an id of "Tips"
contains any data.
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"


eg XML

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

eg XSL

<fo:block id="Tips">
<xsl:for-each select="Scale">
<xsl:variable name="min" select="@min"/>
<xsl:variable name="max" select="@max"/>

<xsl:if test="$score &gt;= $min and $score &lt;= $max">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>

<xsl:if test="NO STATEMENTS PRINTED">
No Tips Sorry
</xsl:if>
</fo:block>
 
R

roy axenov

morrell said:
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:eek:utput
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&gt;=@min) and
($score&lt;=@max)
]
"/>
<block id="Tips">
<xsl:choose>
<xsl:when test="$tips">
<xsl:apply-templates select="$tips" mode="tips"/>
</xsl:when>
<xsl:eek:therwise>
No tips.
</xsl:eek:therwise>
</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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top