472,142 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Setting class on child

Hello,

I am trying to set a class attribute of a text.item element to the value of its nearest ancestor. I want to do this in the case that the class of the text.item is currently a blank string.

<text class="read-only">
...
<text.item class=""/> //this element should inherit the class attribute "read-only" from text
<foo class="read-write">
<text.item class="" /> //this element should inherit the class attribute "read-write" from foo
</foo>
<bar class="read-write">
<text.item class="" /> //this element should inherit the class attribute "read-write" from bar
</bar>
<baz class="read-write">
<bar class="">
<text.item class=""/> //this element should inherit the class attribute "read-write" from baz
</bar>
</baz>
...
</text>

The approach I was considering was creating a template for the text.item node like the following. Is this feasible or would I need to consider an alternative approach?

<xsl:template match="text.item">
<xsl:if test="@class =''">
<xsl:attribute name="class">
<!-- determine the nearest ancestor that has the class attribute set to something other than a blank string, and select that value here-->
<xsl:value-of select="<some expression for my nearest ancestor with class attribute set>"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates/> <!-- the text.item nodes have other children with templates defined already, so delegate accordingly -->
</xsl:template>

Please let me know if more information is needed to give a clearer picture of what I am trying to describe. I apologize in advance if I have mangled any of the terminology.

Thanks,
Valvalis
Feb 27 '07 #1
3 1405
I found the solution, thanks!

<xsl:value-of select="ancestor[@class][1]"/>
Feb 27 '07 #2
dorinbogdan
839 Expert 512MB
Hi,
Glad to see your problem solved.
So, I will close the thread since it got answer.
Mar 21 '07 #3
dorinbogdan
839 Expert 512MB
I re-open the thread in order to allow further comments or suggestions from other members or experts, as per adim request.
Mar 22 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by David McDivitt | last post: by
6 posts views Thread by jalkadir | last post: by
4 posts views Thread by Hollywood | last post: by
2 posts views Thread by Mystery Man | last post: by
reply views Thread by Morten Wennevik | last post: by
11 posts views Thread by alex | last post: by
10 posts views Thread by Goran Djuranovic | last post: by
reply views Thread by leo001 | last post: by

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.