473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 1711

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Philip Meyer | last post by:
1) setting image as Background with alignment in center not working..help Explanation : i need to set a image as background and also it should be dispalyed in the center.i am using apache fop...
0
by: Rary | last post by:
I am using XSL:FO to generate PDF report for my XML, generating it in tables, i want that tables should completely be at one place, if there is a page break , all the contents of the table should...
1
by: Joseph Ferris | last post by:
Hello, I am having an issue with page breaking that I hope someone will be able to help me with. Still a relative "newbie", and I thought this might be a good place to find some help. I have a...
0
by: Nathan | last post by:
Hi, I seem to having a peculiar problem with the display of odd and even pages in XSL-FO. Here is a small background of the problem. My xsl stylesheet mentions my fo:layout-master-set as ...
2
by: TadPole | last post by:
Hi all, My main problems are::::::::: 1. Set a value within a block container that can be used and changed by subsequent templates/block-containers/tables etc.. 2. get/determine/find the...
0
by: annand00 | last post by:
hi! i have a quick question. i have an xsl transform that converts xml to xslfo. The transform generates two <fo:block> 's (say A & B) one after another (A --> B). This is due to the original xml...
2
by: morrell | last post by:
I have a request to find out is there an easy way to solve this little poblem. ___________________ | Block 1 | | | | | | |...
2
by: newatcoding | last post by:
Hello friends, Iam new to this site. I have a problem. I want to know whether the fo:block in velocity template language has any other uses other than equivalent of <p> tag in html. Please help.
1
by: cleary1981 | last post by:
Hi, I am trying to add page numbers to my document in xsl fo. I can get the page numbers to work but I need them to show at the bottom of each page. I know you can define an area as region-after...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.