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

Discussion in 'XML' started by morrell, Oct 10, 2006.

  1. morrell

    morrell Guest

    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>
    morrell, Oct 10, 2006
    #1
    1. Advertising

  2. morrell

    roy axenov Guest

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

    --
    roy axenov
    roy axenov, Oct 10, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Dyer
    Replies:
    5
    Views:
    638
  2. Flip
    Replies:
    3
    Views:
    956
    Tony Morris
    Feb 9, 2004
  3. Steve Kershaw
    Replies:
    1
    Views:
    342
    Brennan Stehling
    Sep 26, 2006
  4. Replies:
    5
    Views:
    911
    X-Centric
    Jun 30, 2005
  5. Mokka

    check if string contains any numbers

    Mokka, Jan 7, 2006, in forum: Javascript
    Replies:
    12
    Views:
    231
    Randy Webb
    Jan 11, 2006
Loading...

Share This Page