By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

Setting class on child

P: 2
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
Share this Question
Share on Google+
3 Replies


P: 2
I found the solution, thanks!

<xsl:value-of select="ancestor[@class][1]"/>
Feb 27 '07 #2

dorinbogdan
Expert 100+
P: 839
Hi,
Glad to see your problem solved.
So, I will close the thread since it got answer.
Mar 21 '07 #3

dorinbogdan
Expert 100+
P: 839
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.