Re: [xsl] explain of Joerg xslt (was: xsl:copy ...)

Subject: Re: [xsl] explain of Joerg xslt (was: xsl:copy ...)
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 8 Apr 2002 10:24:15 -0600 (MDT)
Carsten Klein wrote:
> Yes, this I was trying to say, that the <xsl:template match="...">
> instructs the processor to apply this template to all nodes which
> match this tag. Don't know what is wrong with that.

xsl:template does not cause anything to happen, though.

Think of templates as rules for how to handle certain situations, *if* those
situations should happen to arise. "What to do in case of an emergency" is
not the same as "Cause an emergency" :)

Starting XSLT processing causes only the root node to be processed. If there
are templates that match the root node, the one providing the best match will
be used. The template that matches the root node might contain
xsl:apply-templates or xsl:for-each. It is these instructions that tell the
processor to find some more nodes for processing, and to find the best
matching template for each of those nodes. It is not the xsl:template that
does it.

> Ups

"oops" :)

> Hm, a node does have a starting and ending tag, doesn't it?

A tree is an abstract data structure. You can represent a tree as a string of 
abstract Unicode characters that spell out tags and other markup, and you can 
represent that string of characters as bits & bytes if you apply a character 
map (encoding). In the big picture, it's all one and the same, but we use 
different levels of abstraction depending on what we are doing.

Tags exist at a level of abstraction below the node trees. The tags and other
markup do imply the node tree's structure, but they don't really comprise it.
You will get into trouble if you try to do something like this, which is
something that someone following your advice would think they could do:

    <xsl:if test="somethingTrue">
      </td>
    </xsl:if>

> I mean, this is what I learned when using html.

Forget what you think you know about HTML.

> But nonetheless the xml document description language uses the terms
> start and end tag, or am I completely wrong?

It also uses the terms 'element' and 'attribute', and explains that the tags
are ways to represent these logical/conceptual/abstract items in a linear
document.

XPath/XSLT use XML documents, but conceptually they operate only on a tree of
nodes that is implied by those documents.

> When I wrote this I wanted to emphasize, that the node <tree> was
> only introduced to the output document and that still
> more information written to the output tree would follow, i.e. more
> childnodes and attribute nodes and definetly a ending tag
> to close the <tree> node.
> 
> All wrong? Completely? At least some truth in my words? 

Not really wrong, but not keeping separate certain concepts that will cause
readers trouble later. "tags" is a 4-letter word on this mailing list :) 

You could get away with confusing nodes and tags in HTML, because HTML mixes
declarative and procedural concepts, and HTML user agents have a lot of leeway
in how they are allowed to interpret the contents of an HTML document. 

Once you learn the formal models that XML, XPath and XSLT use, you can go back
into the HTML spec and see that these concepts are much the same there, too.
The difference is that it is easy to use HTML when you only have a partial or
even wrong understanding of how it works, whereas in XML, XPath and XSLT your
processors are not so forgiving, and therefore if you start to learn it
"wrong", you will hit a wall sooner or later, where certain things just don't
fit the model you've invented.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread