Re: [xsl] Match nodes searching for attributes in children

Subject: Re: [xsl] Match nodes searching for attributes in children
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Jan 2010 22:21:33 -0500
At 2010-01-18 04:09 +0100, cvergara@xxxxxxxxxxxxxxxxxx wrote:
Hello Ken and Gerrit,

thanks for your debugging tips. I was making the experiments in a small
test file, not in my development files, so I know there are no mistakes
nor missing namespace prefixes in elements. One curious thing though, I
noticed that my xslt processor (xalan 2.7.1 and the one included in java)
are not able to match attributes. Other people claim something like this
is possible:

<xsl:template match="@attr">
or even:
<xsl:template match="@*">

Even the default template will not match them. An empty stylesheet will
copy only the text elements.

It only copies the text nodes ... it does not copy elements, it acts on element children (not on element attributes).

It will be difficult for me to get help if
the processors behave differently.

They do not behave differently in this regard.

Again you are missing some basic knowledge of XSLT and assuming that things are broken.

Attributes are matched when they are pushed at your stylesheet, but when you use <xsl:apply-templates/> without a select= attribute then only child elements are pushed, not attributes, because in the XPath data model attributes are not children of an element.

When you want to have this acted on:

<xsl:template match="@attr">

... then somewhere in your stylesheet you will need to have used something like:

<xsl:apply-templates select="@*"/>


<xsl:apply-templates select="@attr"/>

Please try and find some basic instruction in XSLT to understand what is going on within the processor. Asking volunteers for help with a specific problem you are having will get a more receptive response than asking volunteers to teach you the language.

And, as Gerrit says, use Saxon ... it is more robust than Xalan. And XSLT 2.0 supports a more feature-rich version of functionality than XSLT 1.0.

I hope this helps.

. . . . . . . . . . . . . Ken

p.s. and, Gerrit, *both* of you appear to be in CEST according to your time stamps and *both* of you should be in bed by now! It is past *my* bed time and I'm in EST!

UBL and Code List training:      Copenhagen, Denmark 2010-02-08/10
XSLT/XQuery/XPath training after 2010-03-15/19
XSLT/XQuery/XPath training:   San Carlos, California 2010-04-26/30
Vote for your XML training:
Crane Softwrights Ltd.
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread