boolean predicate in variable?

Discussion in 'XML' started by =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, May 4, 2007.

  1. Hello guys,

    I was wondering if it was possible to reference a boolean predicate in
    a variable. Basically I want to do with the boolean predicate what you
    would do with any other variable; I want it to apply to many places
    without having to update all those different locations if the
    predicate needs to change.

    This is not a full stylesheet, just snippets of the idea

    <xsl:variable name="list-orphans-widows.properties">
    position()=last()-1 or position()=last()-2 or (position()='1' and
    position()!=last()) or (position()='2' and position()!=last())
    </xsl:variable>

    <xsl:template match="ListB | CELLListB">
    <fo:list-block padding-after="12pt">

    <xsl:variable name="ListBItemsRTF">
    <ListB>
    <xsl:copy-of select="@*"/>
    <xsl:for-each select="ListBItem | CELLListB">
    <xsl:choose>
    <xsl:when test="$list-orphans-widows.properties">
    <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:attribute name="keep-with-next">always</
    xsl:attribute>
    <xsl:apply-templates/>
    </xsl:copy>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:copy-of select="."/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:for-each>
    </ListB>
    </xsl:variable>

    <xsl:for-each select="exsl:node-set($ListBItemsRTF)">
    <xsl:apply-templates select="//ListBItem | //CELLListBItem"/>
    </xsl:for-each>

    </fo:list-block>
    </xsl:template>

    It works cleanly when the predicate is straight up in test="", but the
    predicate yields true in all cases when I try to reference the
    variable. Is what I'm trying to do possible in XSLT?

    Regards
    Jean-Francois Michaud
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, May 4, 2007
    #1
    1. Advertising

  2. Jean-Fran├žois Michaud wrote:

    > I was wondering if it was possible to reference a boolean predicate in
    > a variable. Basically I want to do with the boolean predicate what you
    > would do with any other variable; I want it to apply to many places
    > without having to update all those different locations if the
    > predicate needs to change.
    >
    > This is not a full stylesheet, just snippets of the idea
    >
    > <xsl:variable name="list-orphans-widows.properties">
    > position()=last()-1 or position()=last()-2 or (position()='1' and
    > position()!=last()) or (position()='2' and position()!=last())
    > </xsl:variable>


    You can't store an XPath expression in a variable and evaluate that
    XPath expression dynamically. So your variable above is simply
    containing a result tree fragment with a text node containing some text.
    XSLT 2.0 allows you to define your own functions and call them, that is
    the closest I can think of. Besides processor specific extension
    functions allowing you to evaluate a string with an XPath expression.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 4, 2007
    #2
    1. Advertising

  3. On May 4, 8:28 am, Martin Honnen <> wrote:
    > Jean-Fran├žois Michaud wrote:
    > > I was wondering if it was possible to reference a boolean predicate in
    > > a variable. Basically I want to do with the boolean predicate what you
    > > would do with any other variable; I want it to apply to many places
    > > without having to update all those different locations if the
    > > predicate needs to change.

    >
    > > This is not a full stylesheet, just snippets of the idea

    >
    > > <xsl:variable name="list-orphans-widows.properties">
    > > position()=last()-1 or position()=last()-2 or (position()='1' and
    > > position()!=last()) or (position()='2' and position()!=last())
    > > </xsl:variable>

    >
    > You can't store an XPath expression in a variable and evaluate that
    > XPath expression dynamically. So your variable above is simply
    > containing a result tree fragment with a text node containing some text.
    > XSLT 2.0 allows you to define your own functions and call them, that is
    > the closest I can think of. Besides processor specific extension
    > functions allowing you to evaluate a string with an XPath expression.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/



    Right on, thanks for the answer Martin. I created a function to allow
    for equivalent logic.

    Regards
    Jean-Francois Michaud
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, May 7, 2007
    #3
    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. Jacques

    Predicate by attribute?

    Jacques, Jun 24, 2004, in forum: XML
    Replies:
    2
    Views:
    372
    Jacques
    Jun 24, 2004
  2. awebguynow
    Replies:
    1
    Views:
    354
    George Bina
    Jan 27, 2006
  3. Sabba
    Replies:
    0
    Views:
    625
    Sabba
    May 9, 2006
  4. J Leonard
    Replies:
    4
    Views:
    12,664
    Mark Space
    Jan 19, 2008
  5. Metre Meter
    Replies:
    7
    Views:
    363
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page