xsl-list
[Top] [All Lists]

RE: Transform XML to XML

2005-08-26 07:10:47
At 09:43 AM 8/26/2005, you wrote:
Thanks.

I'm still confused by ".", "*", "node()", etc.  I've read all the
definitions, but somehow I can't grok them.  Any thoughts?

These are all XPath expressions. In fact, they're all Location Paths (a particular type of XPath expression, which happens always to return nodes in the tree, i.e. node sets).

"." is an abbreviation for the XPath expression "self::node()"

"*" is (by itself) an abbreviation for "child::*"

"node()" by itself abbreviates "child::node()"

All Location Paths are made of steps, separated by slashes, as in "secret/rule" (short for "child::secret/child::rule"), a Location Path with two steps.

Each step is made of two parts, an axis specifier (which may be implicit -- these include child::, descendant::, etc) and a node test (which must be explicit). Additionally each step may have one or more predicates, which you recognize by the [ ] syntax (e.g. "secret/rule[(_at_)status='extra-mysterious']", short for "child::secret/child::rule[attribute::status='extra-mysterious'] -- now you can see why abbreviating is nice).

"*" is a "wild card" node test, that matches any node "of the primary node type of the axis" -- so "self::*" and "child::*" (or just plain "*") will match an element, while "attribute::*" (abbreviated as "@*") will match an attribute.

"node()" is also a wild card node test, but matches any node of any type whatsoever.

Location Paths that do not begin with an initial slash "/" are evaluated relative to a context node, in a way analogous to directory traversal syntax on a Unix machine (which XPath syntax is designed to mimic in some respects).

Location paths appear in arbitrary XPath expressions, for example (commonly) in select attributes, as in apply-templates or value-of instructions.

A subset of Location Paths (not all of them, for example most axes are prohibited) is allowed in Patterns (as in the match pattern that identifies when a template can be applied).

Much of the genius of XSLT, for applications for which it's well suited, comes from using these expressions (select expressions and template match patterns) in combination so that your templates provide all conditional logic necessary for the tree to be processed in the order and arrangement you need (which may not be a temporal order, BTW) -- without any explicit "control flow" instructions (xsl:for-each, xsl:if, xsl:choose) at all.

Accordingly, you'll sometimes hear an experienced XSLTer tell a beginner "never use for-each (or if, or choose) -- you don't need it". Which sounds bizarre, but has some truth to it.

I hope this helps,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>