Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > boolean predicate in variable?

Reply
Thread Tools

boolean predicate in variable?

 
 
=?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
Guest
Posts: n/a
 
      05-04-2007
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>
<xsltherwise>
<xsl:copy-of select="."/>
</xsltherwise>
</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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-04-2007
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/
 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
Guest
Posts: n/a
 
      05-07-2007
On May 4, 8:28 am, Martin Honnen <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtle difference between boolean value and boolean comparison? Metre Meter Javascript 7 08-06-2010 08:40 PM
difference between 'boolean' and 'java.lang.Boolean' J Leonard Java 4 01-19-2008 02:56 AM
XPATH Predicate Syntax question Sabba XML 0 05-09-2006 10:48 AM
get position after spec. predicate awebguynow XML 1 01-27-2006 08:42 AM
Predicate by attribute? Jacques XML 2 06-24-2004 11:45 AM



Advertisments