I'm trying to automate some xslt transformations, and I need a way to set xsl:output attributes based on the content in the XML files being transformed.
Specifically, I want to look into the XML files, grab the lang attribute from the root element, and set attributes based on the lang value.
I've tried the following:
<xsl:param name="language">
<xsl:value-of select="//*/@lang"/>
</xsl:param>
<xsl:output method="xml" xmlns:saxon="http://icl.com/saxon" encoding="utf-8">
<xsl:choose>
<xsl:when test="$language != 'ja'">
<xsl:attribute name="saxon:character-representation"><xsl:value-of select="'native'"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="saxon:character-representation"><xsl:value-of select="'hex'"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:output>
...but my parser informs me that the xsl:output element must be empty.
Is there a way to do something like this in the context of a style sheet, or am I going to have to manipulate these attributes at a higher level?
You've tagged this
docbook, which I suspect is why you're still using the ancient Saxon 6.5.5 processor and itshttp://icl.com/saxonnamespace. However, the docbook stylesheets can be made to work with a modern version of Saxon, which allows you to choose serialization attributes dynamically in anxsl:result-documentinstruction.An alternative is to override the
xsl:outputproperties from the Java API or command line. However, that's awkward in your case where you want to make the properties dependent on something in the source document.