boolean predicate in variable?

  • Thread starter =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
  • Start date
?

=?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

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
 
M

Martin Honnen

Jean-François Michaud said:
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.
 
?

=?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

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.


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

Regards
Jean-Francois Michaud
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top