• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Attributr in XPath

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

First there is a XML:



Second there is my XSLT-stylesheet:



Third there is the output:



Everything works fine, there is one mistake only. In the output should not be for instance p6 or p7. There should appear the real names like Marie Dupont or Philippe Dubois. How can I achieve this?

Regards, Urs
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you need to take the value of the attribute, and use that in an XPath expression to find the name of the person it matches? Try using this expression:

<xsl:value-of select="/FAMILYTREE/PERSON[@ID = current()/@MOTHER]/NAME" />

Translates as "find the PERSON with an ID attribute matching the MOTHER attribute of my current node, and take their name".
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or if you expect to do this on larger documents, you might want to consider an <xsl:key> element. The w3schools tutorial about that element has an example which could almost be dropped unchanged into your code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic