• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Get parent node dynamically

 
Ranch Hand
Posts: 264
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am using xsl:key for searching a specified element by its attribute value match. When i find, i try to get its parent node. Can anybody help me. The code for xml is given below.


suppose i create a key as
<xsl:key name="mykey" match="child" use="@id">

and
<xsl:template match="A">
<!-- here i have selected a variable var which has tag child with id=a -->
<xsl:variable name="var" select="key('mykey','a')"/>
<!-- now i want to display two label elemnts -->
<!-- 1. one is of this child element(that i am able to do -->
<xsl:value-of select="$var/label"/>
<!-- 2. and lable of its parent element (Fig1) -->
<!-- HOW TO GET THIS LABEL OF PARENT ELEMENT -->

<!--Finally i need to display : -->

Fig1a

<!-- currently i am able to display only 'a' and not 'Fig1a' -->


</xsl:template>


Edit comment: when posting such XML please use the [ code ] opening and closing tags (without the spaces ofcourse). You described parent and child nodes, but unless it is formatted properly we can't really tell which is the parent and which is the child (your element names do help, but formatting make a lot more meaning.

Thanks.

- m
[ February 08, 2006: Message edited by: Madhav Lakkapragada ]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after you select the child element using the key you defined, you could traverse the Xpath just like in a file system directory.

I would use ../label The '..' takes you one step above where you currently are ie; it takes you to the "parent" element. You then traverse to the label element below it.

- m
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic