xslt of nested elements

Discussion in 'XML' started by webwesen, Oct 20, 2006.

  1. webwesen

    webwesen Guest

    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?
     
    webwesen, Oct 20, 2006
    #1
    1. Advertising

  2. > 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
     
    Joseph Kesselman, Oct 20, 2006
    #2
    1. Advertising

  3. webwesen

    webwesen Guest

    worked as described. thanks a lot.
    and sorry for a newb Q.

    On Oct 20, 4:12 pm, Joseph Kesselman <>
    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
     
    webwesen, Oct 20, 2006
    #3
  4. webwesen

    roy axenov Guest

    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
     
    roy axenov, Oct 20, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    765
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,747
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    651
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    739
    Henry S. Thompson
    Oct 19, 2005
  5. Gerald Aichholzer
    Replies:
    2
    Views:
    2,618
    Gerald Aichholzer
    Jun 27, 2006
Loading...

Share This Page