RE: [xsl] getting the text nodes from a set of attribute nodes

Subject: RE: [xsl] getting the text nodes from a set of attribute nodes
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 04 Sep 2003 15:20:44 -0400

At 02:53 PM 9/4/2003, you wrote:
but that was my point.  the sample XSL i showed for calculating the
minimum value was *treating* a node-set as if the individual elements
were numbers, and was comparing them numerically.

<xsl:value-of select="$nodes[not($nodes &lt; .)]"/>

how would this be interpreted?

As in plenty of other cases in XSLT (1.0), the processor is performing a bit of data type casting for you -- turning nodes into numbers. The rules for this are detailed in the XPath spec. Here, when a node must be construed as a number (required by the less-than operation), it is (a) turned into a string by taking its string value, and (b) then turned into a number following the string-to-number rules you'd expect.

(This particular routine is also relying on a rule of how to compare numerical values with node-sets containing more than one node -- compare each pairing in turn, return true if any are true.)

  the book refers to this as calculating
"the minimum value of a node set", which to my mind is viewing the
"nodes" as numerical values.

Their *values* are numbers (as they are also strings, if we need strings). Any string can be turned into a number ... if it can't, it is anyhow -- the number not-a-number (NaN). And any node can be turned into a string. Ergo, etc.

But really the technique you're citing from the book is robust only in such cases where you know ahead of time the nodes in the set will all cast to numbers cleanly.

  i wasn't trying to suggest that numbers
were actual nodes, only that they were being "treated" that way by
the above expression.

Yes, XPath 1.0 invites this kind of "treat as if" thinking. Most of the time, it's a welcome feature of the language. Sometimes it gets us into tangles.

All of this will change drastically in XPath 2.0, where casts must be made explicitly. Then we get to see what life is like on the other side of the fence.


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

XSL-List info and archive:

Current Thread