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

Re: the Canonical path of a node

  • From: Philippe Poulard <Philippe.Poulard@s...>
  • To: David Carlisle <davidc@n...>
  • Date: Mon, 08 Jan 2007 13:42:58 +0100

Re:  the Canonical path of a node
David Carlisle wrote:
> 
> There are any number of xpath expressions that might select a node,
> 
> /descendant::*[27]
> /*[2]/*[5]/*[1]
> /a/b[2]/c[1]
> id('foo')
> ...

 From a given node, 1 of these XPath expressions (the third) is remarkable :
-it starts from the root
-it descends from child to child until the node given with the name of 
the node or the type test
-it only allow predicates with an index, such as [n]
 From the proposals listed here :
http://lists.xml.org/archives/xml-dev/200403/msg00045.html
I retained "*the canonical path*" for the name of such a path, and the 
predicates must be present for child nodes even if it is [1] : being 
also an XPath pattern, they are easier to apply to a SAX stream :)

I have a class that do that stuff in the RefleX engine :
http://reflex.gforge.inria.fr/javadoc/org/inria/reflex/xml/CanonicalPath.html
If a canonical path have to be inserted in an XML document, the 
namespace declarations can be added to the host element, and eventually, 
the prefixes can be renamed if they overlap.

I didn't notice in the various implementations supplied in XSLT if 
prefixes are remapped if necessary ; this can occur when the same prefix 
is used several times in the path with different namespace bindings ; 
this is why a canonical path is understandable only with its mappings.

For example, if we had this document :
<p:a xmlns:p="p1">
   <p:b xmlns:p="p2">
     <c xmlns="p3"/>
   </p:b>
</p:a>
then the canonical path of <p:c> with its mappings would be :
/p:a[1]/p1:b[1]/nsA1:c
   p    -> "p1"
   p1   -> "p2"
   nsA1 -> "p3"

In RefleX, the xcl:canonical-path() function works in the same way than 
saxon:path() :
<p:c xmlns:p="p3" thePath="{ xcl:canonical-path($theNode) }"/>
the result :
<p:c xmlns:p="p3" xmlns:p1="p1" xmlns:p2="p2" 
thePath="/p1:a[1]/p2:b[1]/p:c[1]"/>

but I'm not sure if the mappings are fixed as well by Saxon (perhaps M. 
Kay could confirm ?) ; they are in RefleX

a variant :
<p:c xmlns:p="p3">{ xcl:canonical-path($theNode) }</p:c>
the result :
<p:c xmlns:p="p3"
   xmlns:p1="p1" xmlns:p2="p2">/p1:a[1]/p2:b[1]/p:c[1]</p:c>

-- 
Cordialement,

               ///
              (. .)
  --------ooO--(_)--Ooo--------
|      Philippe Poulard       |
  -----------------------------
  http://reflex.gforge.inria.fr/
        Have the RefleX !


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.