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

curious behavior of select= and predicates

Subject: curious behavior of select= and predicates
From: "Robert P. J. Day" <rpjday@xxxxxxxxxxxxxx>
Date: Thu, 20 Mar 2003 10:53:42 -0500 (EST)
could not compile select expression
 
  [more pedantics involving simple examples.  the following results
are from "xsltproc", so it may be a processor-related thing.]

cars.xml
--------

<?xml version="1.0"?>

<cars>
 <car>
  <model>mazda mx-6</model>
  <displacement>123</displacement>
 </car>

 <car>
  <model>yugo</model>
 </car>

 <car>
  <model>vette</model>
  <displacement>423</displacement>
 </car>

 <car>
  <model>lamborghini</model>
 </car>

</cars>

dumb.xsl (or at least the only important part of it)
----------------------------------------------------

<xsl:template match="cars">
 <xsl:apply-templates select="car"/>
</xsl:template>

<xsl:template match="car">
 <xsl:value-of select="self::node()[displacement]"/>
</xsl:template>

</xsl:stylesheet>


First puzzler
-------------

  With dumb.xsl as above, i'm using the "car" template to 
decide itself what to return as a result of <xsl:value-of> --
the string-value of the node only if there is a displacement child
element.  *that* works fine (even if it is a silly way to do it.)

  First oddity -- i had always understood that "self::node()" could
be abbreviated as just ".".  but if i replace the select expression
with ".[displacement]", i get the error

================
XPath error Invalid expression
.[displacement]
 ^
compilation error: file dumb.xsl line 13 element value-of
xsl:value-of : could not compile select expression '.[displacement]'
=================

  should i not expect "self::node()[displacement]" to be logistically
equivalent to ".[displacement]"?  or did i misread something?
  
Second puzzler
--------------

  I want the "car" template to return its string value only if it's
the third in context position.  (again, a weird thing to do but humor
me.)  shouldn't i be able to write:

<xsl:template match="car">
 <xsl:value-of select="self::node()[position() = 3]"/>  # just pos 3
</xsl:template>

  instead, i get nothing, even though i've verified that the consecutive
invocations of the "car" template do, in fact, run through the context
positions 1 -> 4 for each "car" element.

  again, have i misread how i can refer to the context node itself
in a select expression?

rday


 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.