Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL/XPath ancestor question

Reply
Thread Tools

XSL/XPath ancestor question

 
 
Colin Fox
Guest
Posts: n/a
 
      12-09-2004
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.

 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      12-10-2004
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.)
 
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
org.apache.jasper.JasperException: Could not find ancestor parseTag pcouas@infodev.fr Java 0 03-07-2005 07:05 PM
How to output the all the ancestor and their attribute of an element ai2003lian@yahoo.com XML 2 02-03-2005 06:03 PM
How to find out the Parent or the Ancestor Node. Eshrath XML 3 10-27-2004 02:47 AM
JTree cut single and multiple child and ancestor nodes not function the right way! Johnny Java 0 10-02-2003 06:44 PM
XML Schema keys, uniqueness based on ancestor's attribute Ognen Ivanovski XML 0 07-15-2003 02:36 PM



Advertisments