[Home] [By Thread] [By Date] [Recent Entries]
At 2013-03-22 14:14 -0700, Martin Holmes wrote:
If I have a template matching an attribute, and producing one in the output tree, like this: The above could be done with: <xsl:template match="@style">
<xsl:copy-of select="."/>
</xsl:template>Is there any way to know the name of the element in the result tree which is the parent of the attribute being created? In the result tree? No. It is write-only and cannot be queried. You'd have to keep track of what you are doing. Some context: I'm turning TEI @style attributes into HTML @style attributes in the output, and I'd like to handle situations in which this kind of input: It is a challenge but you have to keep track yourself. When using XSLT 2.0 something I've done is I've added a tunnel parameter to the apply-templates stack frame indicating that I'm in a DIV and so act on it later when it comes time to do the style attribute ... something along the lines of: <xsl:template match="some-block-element">
<div>
<xsl:apply-templates>
<xsl:with-param name="in-a-div" tunnel="yes" select="true()"/>
</xsl:apply-templates>
</div>
</xsl:template> <xsl:template match="@style">
<xsl:param name="in-a-div" tunnel="yes" select="false()"/>
<xsl:attribute name="style"
select="concat(.,if( $in-a-div ) then ';display:block' else'')"/>
</xsl:attribute>
</xsl:template>Then you just have to remember to add that tunnel parameter for each of the blocks you create so that the processing knows that was done "way back when". I hope this helps. . . . . . . . . Ken
|

Cart



