469,291 Members | 1,742 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,291 developers. It's quick & easy.

boolean predicate in variable?

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:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</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

May 4 '07 #1
2 2396
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/
May 4 '07 #2
On May 4, 8:28 am, Martin Honnen <mahotr...@yahoo.dewrote:
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

May 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by matthias_k | last post: by
18 posts views Thread by Bill Smith | last post: by
3 posts views Thread by Mirek Endys | last post: by
8 posts views Thread by Jeff S. | last post: by
3 posts views Thread by John Dalberg | last post: by
11 posts views Thread by KiranJyothi | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.