[xsl] XSL Template Match using z:row attributes

Subject: [xsl] XSL Template Match using z:row attributes
From: Mark Nahabedian <naha@xxxxxxxxxx>
Date: Wed, 12 Dec 2001 11:34:35 -0500
Michael McCarty writes:
 > I'm kind of new to XSL and am having trouble.  I guess I don't fully
 > understand the way templates are matched or applied.  Any help is greatly
 > appreciated.  I also don't know if the problem is in the namespaces or
 > do I fully understand those.

Here's some introductory text from a presentation I did a few months
ago which might be helpful.


Names and Namespaces

It's conceivable that a single XML document might contain elements and
attributes from more than one schema. Namespaces are a means of
disambiguating names with respect to schemas since there might be
several schemas that have elements with the same string name. For
example, an XSLT transformation script (a.k.a. stylesheet) must
distinguish between XSLT instructions and literal result elements that
happen to have the same names. All elements in the stylesheet which
are not in the XSLT namespace are treated as literal constants by the
XSLT processor. It is by the use of namespaces that such a stylesheet
would distinguish between the XSLT "choose" instruction and an element
named "choose" in an XML schema for describing web-based marketing
questionairs.

An XML namespace is identified by a URI (unifoorm resource
identifier). The format of the target resource is unspecified and in
fact the target resource need not exist. A namespace declaration in an
XML document associates a namespace prefix with the namespace URI. A
name (referred to as a local name in the literature) is prefixed by
the namespace prefix and a colon separator to indicate that the
element name is from that namespace
(e.g. "namespace-prefix:local-name"). This combination of a namespace
and name string is referred to as a qualified name or QName. If a
QName does not have a namespace prefix, that QName is in the current
default namespace. Another way of thinking about this is to realize
that the null namespace prefix is a valid namespace prefix which can
be defined in a namespace declaration and refererenced in a QName.

A namespace declaration is similar in syntax to an XML attribute. It
associates a namespace prefix string with a namespace URI for the
element containing the declaration and for all of its descendants
(unless shadowed by another definition for the same prefix). Thus a
namespace need be defined only once in a document if that definition
is in the top level document element.

The example below is extracted from "draw-knot.xsl" which will be
treated below. Throughout that transformation script the prefix "xsl"
will indicate names in the XSLT transformation language. Names with no
prefix are in the namespace understood by SVG rendering engines.

      <xsl:stylesheet ...
	      xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	      xmlns="http://www.w3.org/2000/svg";>
	...
      </stylesheet>


What the XSLT processor does:

An XML parser parses the input XML document, yeilding a parse tree
(structured in accordance with the XML content model) which is passed
to the XSLT processor. The XSLT processor transforms that input tree
to an output tree based on the provided transformation script
(a.k.a. stylesheet). The resulting tree is serialized to a character
stream (typically XML or HTML).

The processor has the concept of a current node which is initially the
document root node.

The processor looks for the most specific template rule in the
transformation script which matches the current node. It then applies
the body of that template rule. The result of that application is a
result tree fragment, often abbreviated as RTF. The template rule body
may invoke template rule processing with some other node as the
current node (via apply-templates or call-template). The RTF resulting
from that invocation replaces the invocation in the template's output
RTF. The body may also contain literal result elements or construct
additional elements which are to appear in the RTF.



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


Current Thread