xsl-list
[Top] [All Lists]

RE: Boolean Short Curcuit

2005-09-23 02:06:27
Well, this could happen because ancestor::page:error/@name exists, but
doesn't match the name of any document($form-uri)/form/field...

The XPath 2.0 spec says that with an expression (A and B), you've got no
guarantee that B won't be called if A is false. That's different from 1.0,
and it's designed to allow optimization of joins. In fact Saxon will
generally evaluate A first, except in some join predicates: for example

for $i in 1 to 10
for $j in 1 to 10
where ($j gt 5 and $i gt 3)
return x

might be rewritten as

for $i in 1 to 10[. gt 3]
for $j in 1 to 10[. gt 5]
return x

So the message is: you shouldn't be relying on order of evaluation; but in
this case, I don't think that's likely to be the cause of the problem.

The way to avoid reliance on order of evaluation is to rewrite (A and B) as
(if (A) then B else false()). 

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Alan [mailto:alan-xsl-list(_at_)engrm(_dot_)com] 
Sent: 23 September 2005 09:51
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Boolean Short Curcuit

In Saxon 8.(4|5).

I'm calling this function.

<xsl:function name="page:field" as="element()">
  <xsl:param name="name" as="xs:string"/>
  <xsl:sequence select="document($form-uri)/form/field[name = 
$name][1]"/>
</xsl:function>

During this template match. Note that I'm performing a test to see
if the parameter exists. I expect that when it doesn't exist, the
function part of the test will not be called.

<xsl:template
    match="page:message[ancestor::page:error[(_at_)name]
        and page:field(ancestor::page:error/@name)/error]"
    mode="page:page">
<page:message><xsl:value-of
    
select="page:field(ancestor::page:error/@name)/error"/></page:message>
</xsl:template>

But it appears to be getting called.

Recoverable error of :
  XPTY0004: An error occurred matching pattern
  {page:message[ancestor::page:error[(_at_)name] and
        page:field(ancestor::page:error/@name)/error]}
  : An empty sequence is not allowed as the result of 
function page:field()

I can provide more context if necessary. I tried if/else statements
in the call to page:field, but that still produced the error.

Thanks.

--
Alan Gutierrez - alan(_at_)engrm(_dot_)com
    - http://engrm.com/blogometer/index.html
    - http://engrm.com/blogometer/rss.2.0.xml

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>