[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Transform XML to XML

Subject: RE: Transform XML to XML
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 26 Aug 2005 10:10:47 -0400
transform abbreviation
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[@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@xxxxxxxxxxxxxxxx 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 ======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.