RE: xsl:attribute error

> Running Saxon 5.1 results in this error:
> 
> At xsl:attribute on line 10 of file:/S:/projects/xsl/attr.xsl:
> Cannot write an attribute when there is no open start tag
> 
> The XT processor sucessfully processes the document.

My view is that the stylesheet [below] is wrong. It works in xt because xt
does lazy evaluation, so by the time it evaluates the xsl:attribute
instruction there is an element node for the attribute to attach to. But the
spec doesn't require lazy evaluation, and only allows it if it gives the
same effect as immediate evaluation. The spec says that the xsl:with-param
element is instantiated to create a result tree fragment, and the
xsl:attribute element is then instantiated to add an attribute to the root
of the result tree fragment, which is an error because there is no element
node. The implementation is supposed either to signal this error or to
ignore the attribute.

Unfortunately with xsl:attribute the spec does seem to make assumptions
about order of execution: one of the errors described in section 7.1.3
actually uses the word "after".

Mike Kay

	<xsl:template match="node">
		<xsl:apply-templates select="."
mode="duplicate-node-with-attrs">
			<xsl:with-param name="attrs">
				<xsl:attribute name="href">
					<xsl:value-of select="'foobar'"/>
				</xsl:attribute>
			</xsl:with-param>
			<xsl:apply-templates select="*"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="*" mode="duplicate-node-with-attrs">
		<xsl:param name="attrs"/>
		<!-- Copy node -->
		<xsl:copy>
			<!-- Copy existing node attrs -->
			<xsl:copy-of select="@*"/>
			<!-- Override/add param attr -->
			<xsl:copy-of select="$attrs"/>
		</xsl:copy>
	</xsl:template>

Received on Tuesday, 18 January 2000 05:43:37 UTC