473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

xslt of nested elements

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
<fileand not to <violation>.
how can I reference an attribute of the parent tag from the child?

Oct 20 '06 #1
3 2013
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
Oct 20 '06 #2
worked as described. thanks a lot.
and sorry for a newb Q.

On Oct 20, 4:12 pm, Joseph Kesselman <keshlam-nos...@comcast.net>
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
Oct 20 '06 #3

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

Oct 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
2
by: Peter Gerstbach | last post by:
Hello, I need help on the new xsl:document element! I'm using XSLT version 1.1 to be able to use the <xsl:document> element, because I need more than 1 output files. I'm using Saxon 6.5.3 My...
6
by: Gary Huntress | last post by:
Hi, I'm having trouble with an xslt transform. I'm trying to transform a vector into an array of width N. For example here is my vector: <data> <x id="1">1.2</x> <x id="2">.2</x> <x...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
3
by: meyer.dominik | last post by:
Hi there! I'm a newbie in XSLT, so maybe this problem is easy to solve, but I just don't get it and hours of searching for an answer didn't help me either. Is there any possibility to print a...
3
by: Philipp Schumann | last post by:
Hi, I have several nested layers of <node> element that are processed by an XSLT template. Is there any possibility to determine the depth of a node in the overall nesting hierarchy? For...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
7
by: C.W.Holeman II | last post by:
For info on the context of my question see the end of this posting. From http://www.w3.org/TR/XHTMLplusMathMLplusSVG/: How can I validate the result of client-side XSLT transform which has...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.