471,056 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,056 software developers and data experts.

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

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>

Oct 10 '06 #1
1 1562

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

Oct 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Rary | last post: by
1 post views Thread by Joseph Ferris | last post: by
reply views Thread by Nathan | last post: by
reply views Thread by annand00 | last post: by
2 posts views Thread by newatcoding | last post: by
1 post views Thread by cleary1981 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.