473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2561
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hall | last post by:
I accidently overloaded a static member function that I use as predicate in the std::sort() for a vector and ended up with a compiler error. Is this kind of overload not allowed for predicates and...
5
by: matthias_k | last post by:
Hi, I need to sort elements of a std::list using a function predicate, something like: bool predicate( const& M m1, const& M m2 ) { return m1.somedata < m2.somedata; } I tried to call...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
3
by: Mirek Endys | last post by:
Is there a possibility to write an Predicate with param? I need to look for a value in Array, or in List, but this value is variable. How do I write something like this: class MyObject {...
8
by: Jeff S. | last post by:
I was recently advised: << Use List<struct> and Find() using different Predicate delegates for your different search needs.>> What is "Predicate delegate" as used in the above recommendation? ...
3
by: John Dalberg | last post by:
I have seen examples for List<T>.FindAll(findthis)where findthis is a predicate. How do I pass a parameter to this predicate so that I have different values to search for? I don't want to use...
3
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
5
by: Ganesh | last post by:
hi ! Can the predicate function used in std::sort take optional arguments ? For instance. I have a class Point. I create a vector of this and then want to compare the slopes of these points with...
11
by: KiranJyothi | last post by:
Hello All, I am writing a code in C where I have to use the Boolean data type. I am doing - typedef int flag; #define FALSE 0 #define TRUE 1 void main()
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.