RE: [xsl] understanding attributes and predicates

Subject: RE: [xsl] understanding attributes and predicates
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 1 Feb 2008 22:10:05 -0000
> When I select specific par elements with a predicate, as in 
> the template below, I get the attribute name, attribute 
> value, and the text node of the <par> element.
> 
> <xsl:template match="par[@class='stem_mc']">
>    <!-- List the attribute names and values. --> 
> <xsl:for-each select='@*'>
>    attribute name: <xsl:value-of select="name()"/> attribute 
> value: <xsl:value-of select="."/> </xsl:for-each>
>    </xsl:template>
> 
> 
> I just wonder what is going on. Is it the "for-each 
> select='@*'" or the "value-of select="." that is returning 
> the text node of the par element?

I don't know exactly what's going on, but what I would expect to happen is
this:

(a) when you get to a par element with class="stem_mc", you output all the
attribute names and values

(b) when you get to a par element without class="stem_mc", you output the
text value of the element.

That's because there are built-in template rules in every stylesheet that
look like this:

<xsl:template match="*">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()">
  <xsl:value-of select="."/>
</xsl:template>

When you get to a par element that doesn't match par[@class='stem_mc'],
these built-in template rules cause the text nodes within the element to be
output.

If this explanation doesn't seem to fit what you're observing, then I've
probably misunderstood your explanation about what's in your stylesheet.
Submit a *complete* stylesheet and show its output.

Michael Kay
http://www.saxonica.com/

Current Thread