XSL: Returning a selected node in the context of it's ancestors

Subject: XSL: Returning a selected node in the context of it's ancestors
From: "дл" <james@xxxxxxxxxxx>
Date: Tue, 19 Oct 1999 19:02:34 +0100
Has anyone tried to use XSL to return a document fragment that includes the
necessary parent nodes for a selected node, so that the lineage of the
selected node is maintained?  I've got this working using the ancestor()
function recursively, but of course this returns the nodes inside out - i.e.
parent, then grandparent, then greatgrandparent etc.  What I really want to
do is go back to the root, and then copy the intermediate nodes down to the
node that was selected.

For example, given the document

<vendor name="james">
 <product id="1234">
  <material>SiO2</material>
 </product>
 <product id="5678">
  <material>CO2</material>
 </product>
</vendor>

and a stylesheet fragment

<xsl:for-each select="/vendor/product/material[.='SiO2']">

to return the fragment

<vendor name="james">
 <product id="1234">
  <material>SiO2</material>
 </product>
</vendor>

p.s Using IE5, but if anyone has any sample code for another parser I'd love
to see it.

Best regards,
James Carlyle

www.xmltree.com - directory of XML content on the web




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread