[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