XSL/XPath ancestor question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin Fox

    XSL/XPath ancestor question

    Hi, all.

    Within an xsl template, you can use the <xsl:attribut e> 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:f ield" mode="single">
    <xsl:choose>
    <xsl:when test="@type='ht mltextarea'">
    <xsl:attribut e name="{../../onsubmit}">subm itEditForm()</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.

  • Johannes Koch

    #2
    Re: XSL/XPath ancestor question

    Colin Fox wrote:
    [color=blue]
    > Hi, all.
    >
    > Within an xsl template, you can use the <xsl:attribut e> 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:f ield" mode="single">
    > <xsl:choose>
    > <xsl:when test="@type='ht mltextarea'">
    > <xsl:attribut e name="{../../onsubmit}">subm itEditForm()</xsl:attribute>[/color]

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

    <xsl:template match="myform:f orm">
    <form>
    <xsl:choose>
    <xsl:when test="foo:bar/myform:field/@type='htmltext area'">
    ...
    </xsl:template>
    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)

    Comment

    Working...