XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] 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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS