|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: baffled by <xsl:template match="/">
Kenny,
At 01:07 PM 5/11/2004, you wrote: In Michael Kay's book, XSLT Programmer's Reference - 2nd Edition, the top of page 75 says that the pattern "/" matches the root node. I have always been baffled by this, because I have never seen "/" match the root node when using <xsl:template match="/">. You've been caught by one of the few terminological gotchas of XSLT/XPath. XPath posits a "root node" to be the parent of the root element of the document, which we try to call the "document element" in order to alleviate exactly this confusion. So the "root node" is not what you think it is (that element you've named "root"). The XPath model finds it convenient to have this root node for several reasons: * Since as children it can have not only the document element, but also comments and PIs that are siblings of that element, the latter have a place in the model. (If the root were that element, we'd need a way to have siblings without a parent.) * Since the document element is now the child of something, it can be matched by the expressions "*" (short for child::*, that is any child element) or "root" (for child::root -- this likewise has to be someone's child for it to match). ... and perhaps others that elude me at the moment. In any case, this is the kind of thing you can learn in a formal exposition of XPath. So while match="/" matches the root node, match="/*" is short for match="/child::*", which matches the document element (the only element child of the root), no matter what it's named. The actual root is referred to by the XPath "/", but has no name as such (which accounts for the behavior of your stylesheet). Cheers, Wendell and the following XSL ====================================================================== 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 ======================================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








