[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: value of variable inside a condition doesn't work?

Subject: Re: value of variable inside a condition doesn't work?
From: Mike Brown <mike@xxxxxxxx>
Date: Tue, 28 Jan 2003 20:42:55 -0700 (MST)
xslt value of variable
Tobias Reif wrote:
> Mike Brown wrote:
> 
> > [...] <x><y/></x>. <y/> can be written as <xsl:foo/>
> 
> 
> Could you elaborate?

If y = f(z), then the inverse is true: f(z) = y.
If x also equals y, then x = f(z), and f(z) = x.

The equality expressions above are all just assertions of identity and of the
relationships between variables. They are just statements of fact. "If f(z)
were evaluated, it would be y. In other words, f(z) *is* y."  This is entirely
different than saying "You, you there with the finger in your ear! Evaluate
f(z) and tell me what you get! What's that? It's y? Ah, thank you very much!
I never would have known!"

OK, so now consider that <x><y/></x> is the XML equivalent of x = y.  It is
declaring an immediate relationship between thing x and thing y. When in a
template in your stylesheet, it is a declaration that the result tree contains
an element x which contains empty element y.

If the evaluation of <ext:foo/> would produce a node-set containing an empty
'y' element, then

<x><ext:foo/></x>  =  <x><y/></x>

...you could write one or the other and it would mean exactly the same thing.

The XSLT processor can, in theory, know this, and can optimize accordingly,
remembering that <ext:foo/> is <y/> and shortcutting the evaluation after the
first time, just using <y/> whenever it sees <ext:foo/> and all other factors
that would influence how it is evaluated (including what XSLT calls the
context) are the same.

This also applies perhaps a little more concretely to functions in an XPath
expression. The XPath engine is free to optimize by remembering that function
foo() is a certain object, as long as it is called with the same arguments.

So if you were counting on <ext:foo/> sometimes being <y/>, sometimes <z/>,
and foo() sometimes being 'bar', sometimes 'baz', then you might be surprised
when an XSLT processor chooses go through the motions of evaluating <ext:foo/>
and foo() only once during the transformation.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.