XSL/XPath ancestor question

Discussion in 'XML' started by Colin Fox, Dec 9, 2004.

  1. Colin Fox

    Colin Fox Guest

    Hi, all.

    Within an xsl template, you can use the <xsl:attribute> tag to set an
    attribute of the current output node. This is great.

    However, I need to be able to set an attribute of an ancestor node.

    Here's the relevant part of my xsl:

    <xsl:template match="myform:field" mode="single">
    <xsl:choose>
    <xsl:when test="@type='htmltextarea'">
    <xsl:attribute name="{../../onsubmit}">submitEditForm()</xsl:attribute>

    This doesn't work -- the parser rejects the "../../" syntax on the name.
    Also, this particular technique (even if it worked) is fragile, because
    what I really want to do is to set the 'onsubmit' attribute of the Form
    parent element, which is at a potentially arbitrary level above the
    current node.

    So -- is there an XPath selector that I can use in the name field of the
    attribute node to set the value of the Form parent, or do I have to do a
    select at this point and select the parent? And if so, what would that
    select look like? (I haven't done any backwards search selectors yet).

    Thanks in advance,
    cf


    --
    Colin Fox
    President
    CF Consulting Inc.
    Colin Fox, Dec 9, 2004
    #1
    1. Advertising

  2. Colin Fox wrote:

    > Hi, all.
    >
    > Within an xsl template, you can use the <xsl:attribute> tag to set an
    > attribute of the current output node. This is great.
    >
    > However, I need to be able to set an attribute of an ancestor node.
    >
    > Here's the relevant part of my xsl:
    >
    > <xsl:template match="myform:field" mode="single">
    > <xsl:choose>
    > <xsl:when test="@type='htmltextarea'">
    > <xsl:attribute name="{../../onsubmit}">submitEditForm()</xsl:attribute>


    You should make the xsl:choose on the grandparent element, and add the
    attribute in the template for the grandparent.

    <xsl:template match="myform:form">
    <form>
    <xsl:choose>
    <xsl:when test="foo:bar/myform:field/@type='htmltextarea'">
    ...
    </xsl:template>
    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)
    Johannes Koch, Dec 10, 2004
    #2
    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. Johnny
    Replies:
    0
    Views:
    890
    Johnny
    Oct 2, 2003
  2. Replies:
    0
    Views:
    338
  3. Replies:
    1
    Views:
    3,596
    A. Bolmarcich
    May 27, 2005
  4. werD
    Replies:
    2
    Views:
    1,906
    Peter Flynn
    Aug 28, 2006
  5. Ebenezer
    Replies:
    7
    Views:
    847
    Richard Tobin
    Oct 25, 2008
Loading...

Share This Page