Re: [xsl] Determining the context node

Subject: Re: [xsl] Determining the context node
From: Evan Lenz <evan@xxxxxxxxxxxx>
Date: Fri, 14 Apr 2006 00:23:14 -0700
Allison Bloodworth wrote:
Hi Evan & everyone,

Thanks very much for your help--the context node has often confused me and
this message from Evan is the most helpful information on it I've ever
gotten (especially the part about for-each and apply-templates being the
only things that change it). <xsl:value-of select="name()"/> is exactly what
I was looking for.
Great! I'm glad it was helpful.

Re: xsl:copy, since I didn't know how to get the name of the node, I was
trying to print out the content of the node using either xsl:copy or
xsl:copy-of. I would think the only real way you could do this is to use
xsl:copy...with xsl:copy-of if the current node had no text content (and
perhaps contained other elements), you would get the text content of all the
element(s) below it so you couldn't really tell what node you were on if you
were in a deep tree structure. The problem with xsl:copy, however, was that
if you were on a node with no text content itself (e.g. the node only
contained other elements) you would get nothing.
For all node types except for elements, <xsl:copy/> behaves exactly the same as <xsl:copy-of select="."/>

<xsl:copy> differs from <xsl:copy-of select="."> only when the current node is an element. The purpose of <xsl:copy> is to create a shallow copy of the element (just the start and end tags, if you will). The content of the element in the result depends on the content of <xsl:copy> in the stylesheet.

If the current node is an element, <xsl:copy> won't ever give you "nothing". At minimum, it will give you an empty element. I suspect you're only interested in seeing the text content, and perhaps because you're viewing the result in a browser?

Evan

Current Thread