Re: [xsl] Getting epub: namespace into root html element

Subject: Re: [xsl] Getting epub: namespace into root html element
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Jun 2014 10:37:00 -0000
Wendell Piez wapiez@xxxxxxxxxxxxxxx <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
dinsdag 24 juni 2014 15:41


<xsl:template match="@*|node()">
<xsl:copy>
<xsl:namespace name="epub">http://www.idpf.org/2007/ops</xsl:namespace>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

(Note: untested. In particular I haven't checked what will happen to
comments and processing instructions are matched with this template --
instead, trusting the language designers to have specified the right
thing, i.e. that the xsl:namespace instruction is then ignored.)

Indeed, the xsl:namespace instruction will be ignored or used for all node types except document nodes, which will raise an error. In addition, if the stylesheet is complex, you may want to just add the namespace node to the root node, so that you do not have to add it to all your other node creation instructions:


<xsl:template match="/*">
<xsl:copy>
<xsl:namespace name="epub">http://www.idpf.org/2007/ops</xsl:namespace>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

The namespace will then be bound to every node in your result. Consequently you will see it declared on the document element in your output -- and probably nowhere else. (I say 'probably' because that is the way a well-designed serializer will do it, other things being equal.)

Yes, the namespace fixup process will take care of it (see http://www.w3.org/TR/xslt20/#namespace-fixup).


Cheers,
Abel

Current Thread