BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


XSLT
Get the last item from a delimited list
Limitation to Muenchian method.
Find the number of tokens or words in a string
Randomization of node-sets or node-lists
XPath Analyzer
Finding the Maximum Date
World Cup 2002 fever hits XSLT!!
Using XSLT for DHTML Menus
RSS / RDF Newsfeed Reader
Hierarchical menu from Database + XSL to Html
XSLT syntax hightlighter
XSLT Stylesheet for listing namespaces used in a document
Rotate an SVG shape over it's center
Looping through each letter of the alphabet
An XSL Calculator using the FXSL Functional Programming Library
A Calendar, using the XSelerator's datetime library
Match a phrase to the closest sorted list value with 1 XPath Expression
SVG toolbar
Sort an XML document
Transposing rows into columns using XML/XSLT


 
 

<< XQuery.NET and XML >>


By Dimitre Novatchev
First Posted 04/27/2002
Times viewed 191

Finding ""the corresponding node"" in a parallel subtree


Summary Specifies a unique node identification method, which is used in solving the particular problem of finding "the corresponding node" in a parallel subtree

From: http://sources.redhat.com/ml/xsl-list/2002-04/msg01308.html > > I need to quickly find the matching node to the current node > > which is in a parallel branch with identical structure to the > > branch I'm operating in. It seems like this should be really > > simple, but the only solution I can come up with is > > a recursive template to assemble the name of the path from > > the branch tag down, and then compare that against the result > > from the same template for each node in the second tree. The > > trees may be of arbitrary depth. Any other ideas? > One XPath expression that returns the required corresponding node is: $br2//node() [count(preceding::node()) - $br2PrecIndex = $thisRelPrecIndex and count(ancestor::node()) - $br2AncIndex = $thisRelAncIndex ~ where there are the following variable definitions: This might seem a little bit complicated, however the idea is quite simple. Every node can be identified in a two-dimensional coordinate system, in which the first axis is the "preceding" axis, and the second axis is the "ancestor" axis (as we know, these two axes are non-overlapping). That is, the pair: (count(preceding::node()), count(ancestor::node())) uniquely identifies any node. The above is an absolute coordinate system (relative to the root node). We can express the pair of coordinates of a node relative to some ancestor (in our case "branch1"). Then the corresponding node in the subtree rooted by "branch2" must have the same pair of coordinates, relative to "branch2". This simple relationship is expressed in the first XPath expression in this message. Cheers, Dimitre Novatchev.

Additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< XQuery.NET and XML >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML