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

Re: backtracking to find all parents till root[again]

Subject: Re: backtracking to find all parents till root[again]
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Tue, 24 May 2005 15:04:02 +0000
xsl find
Rahil,

It's still not a watertight problem statement, but the following will produce what you want, and I imagine you can press it into better service if need be.

<?xml version="1.0" encoding="iso8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes"/>


   <xsl:template match="/">
       <xsl:variable name="find" select="'NextTime'"/>

<xsl:apply-templates select="Top/SubConcepts/SubConcept/Value[contains(., $find)]"/>
<xsl:text>Parent: SubConcepts</xsl:text>
</xsl:template>


   <xsl:template match="Value">
       <xsl:text>Match Found: </xsl:text><xsl:value-of select="."/>
       <xsl:text>&#xa;</xsl:text>

       <xsl:apply-templates select="parent::SubConcept[1]"/>
   </xsl:template>

   <xsl:template match="SubConcept">
       <xsl:text>Parent: </xsl:text><xsl:value-of select="@name"/>
       <xsl:text>&#xa;</xsl:text>

<xsl:apply-templates select="preceding-sibling::SubConcept[contains(Value, current()/@name)][1]"/>
</xsl:template>


</xsl:stylesheet>


Regards,


--A

How do I backtrack to the root element from the result-generating node? Hence if my given structure is of the form:

<Top>
   <SubConcepts>
         <SubConcept id="990" name="Level1">
               <Child ref="567">Child1</Child>
               <Value ref="456">hasFeature BrokenBolt</Value>
         </SubConcept>
         <SubConcept id="456" name="BrokenBolt">
               <Child ref="345">Child2</Child>
               <Value ref="123">hasProperty NextTime</Value>
         </SubConcept>
   </SubConcepts>
</Top>

I find my result in the <Value ref="123"> node with the contained value 'Time'. I can find the parent of this with the @name

Match found: Next
Parent: BrokenBolt
         Parent: Level1
         Parent: SubConcepts

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Current Thread

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
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.