[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] logical and, and logical or


Subject: Re: [xsl] logical and, and logical or
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sun, 17 Sep 2006 19:50:56 -0700

Actually, I don't need these functions.  It's just that I was looking for a
logical and, and because I thought that every operator was backed by at least
one function, I looked for a respective function.  Since I didn't find such a
function I came to the conclusion that XPath might not provide a logical and.
When I said that I was missing the corresponding functions, I just wanted to
explain why I thought that XPath doesn't provide an and.


As others have explained, XPath *provides* the operators "and" and "or". And this is well expressed in the XPath 2.0 specification: http://www.w3.org/TR/xpath20/#doc-xpath-OrExpr

It seems to me that you're expecting that the "backing functions"
described in the "F & O" spec actually exist in the language -- this
isn't so. To quote this document:

 " Functions defined with the op prefix are described here to
underpin the definitions of the operators in [XML Path Language
(XPath) 2.0], [XQuery 1.0: An XML Query Language] and [XSL
Transformations (XSLT) Version 2.0]. These functions are not available
directly to users, and there is no requirement that implementations
should actually provide these functions. For this reason, no namespace
is associated with the op prefix."

In case such functions really need to be referenced in XPath
expressions, one cah use the FXSL functions:

   f:and()
and
   f:or()

where the prefix "f" is bound to the FXSL namespace "http://fxsl.sf.net"

The existence of these functions is necessary and becomes really
useful if we need to pass them as parameters or to create their
partial applications.


for example, here's the definition of the function f:allTrue() (returning the boolean value of whether all items in a sequence are true() or not), which uses f:and()


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://fxsl.sf.net/" exclude-result-prefixes="f xs"

 <xsl:import href="func-foldl.xsl"/>
 <xsl:import href="func-Operators.xsl"/>

 <xsl:function name="f:allTrue" as="xs:boolean" >
   <xsl:param name="pList" as="xs:boolean*"/>

   <xsl:copy-of select="f:foldl(f:and(), true(), $pList)"/>
 </xsl:function>
</xsl:stylesheet>



Hope this helped.

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk


On 9/14/06, Wolfgang Jeltsch <wolfgang@xxxxxxxxxxx> wrote:
Am Donnerstag, 14. September 2006 19:03 schrieb Abel Braaksma:
> Wolfgang Jeltsch wrote:
> > Hmm, I recognize that there are respective operators now but I was (and
> > am still) missing the corresponding functions.
> >
> > Best wishes,
> > Wolfgang
>
> If you really want a function, you can do it in XSLT 2:
>
> <!-- acts as an and() function with two params -->
> <xsl:function name="yourns:and">
>       <xsl:param name="prefix" />
>       <xsl:param name="postfix" />
>       <xsl:value-of select="$prefix and $postfix" />
> </xsl:function>
>
> <!-- acts as an or() function with two params -->
> <xsl:function name="yourns:or">
>       <xsl:param name="prefix" />
>       <xsl:param name="postfix" />
>       <xsl:value-of select="$prefix or $postfix" />
> </xsl:function>
>
> But tell me, really, was this what you were looking for? A function as a
> replacement of an operator?
>
> Cheers,
> Abel Braaksma
> http://abelleba.metacarpus.com

Actually, I don't need these functions.  It's just that I was looking for a
logical and, and because I thought that every operator was backed by at least
one function, I looked for a respective function.  Since I didn't find such a
function I came to the conclusion that XPath might not provide a logical and.
When I said that I was missing the corresponding functions, I just wanted to
explain why I thought that XPath doesn't provide an and.

Best wishes,
Wolfgang




--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk


Current Thread
Keywords