Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt of nested elements

Reply
Thread Tools

xslt of nested elements

 
 
webwesen
Guest
Posts: n/a
 
      10-20-2006
hello,

an xsl virgin here... please be gentle...

got the following xml (PMD output):
================================
<file name="abc.java">
<violation line="108">
Avoid unnecessary return statements
</violation>
<violation line="179">
Avoid unnecessary return statements
</violation>
</file>
================================

and an xsl (irrelevant lines skipped):
================================
<xsl:template match="file" mode="pmd">
<xsl:value-of select="@name"/>
<xsl:apply-templates select="violation" mode="pmd"/>
</xsl:template>

<xsl:template match="violation" mode="pmd">
<xsl:value-of select="@name"/> <!-- AAA -->
<xsl:value-of select="@line"/>
</xsl:template>
================================

and the line (marked with AAA) is obviously wrong... @name belongs to
<file> and not to <violation>.
how can I reference an attribute of the parent tag from the child?

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      10-20-2006
> how can I reference an attribute of the parent tag from the child?

"..", or "parent::*", or "ancestor::*[1]", or (in this case)
"parent::file" or "ancestor::file" or...

To take the simplest solution:
<xsl:value-of select="../@name"/>



--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
 
webwesen
Guest
Posts: n/a
 
      10-20-2006
worked as described. thanks a lot.
and sorry for a newb Q.

On Oct 20, 4:12 pm, Joseph Kesselman <(E-Mail Removed)>
wrote:
> > how can I reference an attribute of the parent tag from the child?"..", or "parent::*", or "ancestor::*[1]", or (in this case)

> "parent::file" or "ancestor::file" or...
>
> To take the simplest solution:
> <xsl:value-of select="../@name"/>
>
> --
> Joe Kesselman / Beware the fury of a patient man. -- John Dryden


 
Reply With Quote
 
roy axenov
Guest
Posts: n/a
 
      10-20-2006

webwesen wrote:
> got the following xml (PMD output):
> ================================
> <file name="abc.java">
> <violation line="108">
> Avoid unnecessary return statements
> </violation>
> <violation line="179">
> Avoid unnecessary return statements
> </violation>
> </file>
> ================================
>
> and an xsl (irrelevant lines skipped):
> ================================
> <xsl:template match="file" mode="pmd">
> <xsl:value-of select="@name"/>
> <xsl:apply-templates select="violation" mode="pmd"/>
> </xsl:template>
>
> <xsl:template match="violation" mode="pmd">
> <xsl:value-of select="@name"/> <!-- AAA -->
> <xsl:value-of select="@line"/>
> </xsl:template>
> ================================
>
> and the line (marked with AAA) is obviously wrong...
> @name belongs to <file> and not to <violation>.
> how can I reference an attribute of the parent tag
> from the child?


Parent node, not 'tag'. Naturally, you need to use the
parent axis:

<xsl:value-of select="parent::*/@name"/>

or, using a shortcut:

<xsl:value-of select="../@name"/>

Reading an XPath tutorial would've gotten you there in five
minutes or so.

--
roy axenov

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
Multiple XSLT Transforms using a Controller XSLT sneill@mxlogic.com XML 2 10-19-2005 11:00 AM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
xslt alone or xslt/java for static site? ted XML 1 01-26-2004 10:41 AM
[XSLT]Passing values from Javascript to a XSLT variable Benjamin Hillsley XML 3 09-25-2003 04:50 AM



Advertisments