LISTSERV mailing list manager LISTSERV 15.5

Help for XML-L Archives


XML-L Archives

XML-L Archives


View:

Next Message | Previous Message
Next in Topic | Previous in Topic
Next by Same Author | Previous by Same Author
Chronologically | Most Recent First
Proportional Font | Monospaced Font

Options:

Join or Leave XML-L
Reply | Post New Message
Search Archives


Subject: Re: XSLT default rules
From: "G. Ken Holman" <[log in to unmask]>
Reply-To:General discussion of Extensible Markup Language <[log in to unmask]>
Date:Fri, 10 Dec 1999 15:53:20 -0500
Content-Type:text/plain
Parts/Attachments:
Parts/Attachments

text/plain (81 lines)


At 99/12/09 09:24 +0000, Sebastian Jekutsch wrote:
>A simple question about XSLT default rules. In the recommendation there is
>a default rule as this:
>
><xsl:template match="text() | @*">
>     <xsl:value-of select="."/>
></xsl:template>
>
>So, if you have a XML source
>
><class name="Fred">
>     <method>exit</method>
></class>
>
>and an XSLT sheet
>
><xsl:template match="Fred">
>     <xsl:apply-templates/>
></xsl:template>
>
>it will result -- according to the default rule -- into
>
>Fredexit
>
>Is that right?

Nope.

>Or did I get it wrong?

Yup.

>I'm a bit surprised because this
>behaviour doesn't make any sense to me. I cant think of
>any example where this behaviour is useful. Who needs the attribute values?
>I'm ok with
><xsl:template match="text()">
>     <xsl:value-of select="."/>
></xsl:template>
>but not with the @* in it.

It is safe to have it there because <xsl:apply-templates/> will process the
child nodes and attributes are not children ... they are associated in a
relationship that isn't a child relationship (though, asymmetrically, the
parent of an attribute node is the element node to which they are attached).

>O.K., I browsed through the Data Model section in XPath and found the
>following:
>
>"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."

Whoops ... I didn't read ahead enough.

>Sorry, but that's simply nonsens, isn't it? However, that would solve my
>problem.....

>Every hint or comment is welcome!

Section 5.4 states "A select attribute can be used to process nodes
selected by an expression instead of processing all children."  Since you
don't have the select attribute, then only child nodes are processed.  When
only child nodes are processed, then the associated attribute nodes are
skipped.

I wouldn't call it nonsense, though I admit the asymmetry is sometimes
confusing with students.

I hope this helps.

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

--
G. Ken Holman                    mailto:[log in to unmask]
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/l/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Web site: XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-03-9
Next instructor-led training:              1999-12-05/06, 1999-12-07,
-                            2000-02-27/28, 2000-05-11/12, 2000-05-15

Back to: Top of Message | Previous Page | Main XML-L Page

Permalink



LISTSERV.HEANET.IE

CataList Email List Search Powered by the LISTSERV Email List Manager