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