This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: "*|@*|text()" vs. "node()"
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] "*|@*|text()" vs. "node()"
- From: Francis Norton <francis at redrice dot com>
- Date: Thu, 04 Oct 2001 14:44:15 +0100
- References: <3BBC5ABA.2020707@gmx.de>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Jörg,
Jörg Heinicke wrote:
>
> I want to shorten/improve my XSL-code, but a problem occures. Until now I
> had a stylesheet like the following:
>
> <xsl:template match="*|@*|text()">
> <xsl:copy>
> <xsl:apply-templates select="*|@*|text()"/>
> </xsl:copy>
> </xsl:template>
>
Take a look at the XSLT spec for the "identity transform"
(http://www.w3.org/TR/xslt.html#copying). Their identity transform uses
<xsl:template match="@*|node()">
Then look under patterns and you find the XSLT definition of the node()
test:
node() matches any node other than an attribute node and the root node
which is slightly confusing since the XPath spec defines it as:
A node test node() is true for any node of any type whatsoever.
So then maybe it isn't the match that's wrong, maybe it's the select -
so look under attribute in XPath
(http://www.w3.org/TR/1999/REC-xpath-19991116#attribute-nodes)
Each element node has an associated set of attribute nodes; the element
is the parent of each of these attribute nodes; however, an attribute
node is not a child of its parent element.
So <xsl:apply-templates select="node()"/> is short for
<xsl:apply-templates select="child::node()"/>, and attributes aren't on
the child axis of their parent element.
So you should be able to re-write the XSLT identity transform as
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
but that *doesn't* work - it drops attributes - so I guess the XSLT
definition of node() applies rather than the XPath one.
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list