• 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

Simple XSL problem: parent attributes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My XML looks like this:

<A name"alpha">
<B id="0">zero</B>
<B id="1">one</B>
</A>

What I want to output is this:

alpha:zero
alpha:one

If I use some XSL to style this...

<xsl:for-each select="A\B">
<xsl:value-of select="???" />:<xsl:value-of select="." />
</xsl:for-each>

...what do I use in ??? to select the parent attribute @name? What if B has an attribute @name too? Are there any other ways to do this that you can think of?

*had to disable similies :P
[This message has been edited by Dave Flynn (edited May 09, 2001).]
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave, you can use <xsl:value-of select="../@name"/> construction
".." is a shorthand for parent axis, so "../@name" will select name attribute of parent element only.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave,
I am posting both xml file and xsl file which will produce
the result you want. This is based upon what Mapraputa has said.
XML File: "1.xml"
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="1.xsl"?>
<A name="alpha">
<B id="0">zero</B>
<B id="1">one</B>
</A>
XSL File: "1.xsl"
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<xsl:apply-templates />
</html>
</xsl:template>
<xsl:template match="A">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="B">
<P>
<xsl:value-of select="../@name"/> :
<xsl:value-of select="."/>
</P>
</xsl:template>
</xsl:stylesheet>
Regards
Sanjay
 
reply
    Bookmark Topic Watch Topic
  • New Topic