[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Getting epub: namespace into root html element
Subject: Re: [xsl] Getting epub: namespace into root html element From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 24 Jun 2014 13:41:15 -0000 |
Dear Peter, Whether a DOCTYPE declaration is required on an HTML5 document isn't really arguable: it's up to the specification, which says that (yes) it's optional when using the XHTML5 syntax, but not when using the HTML5 syntax. (I am referring to http://dev.w3.org/html5/html-author/#doctype-declaration, which I am taking to be normative for these purposes.) (Whether any particular HTML5 processor will behave correctly when the DOCTYPE declaration is missing is a different question, and, I suppose, subject to an argument about what "correctly" means in a given case. But that's not about HTML5; it's about the processor.) But you're asking about namespaces -- which are confusing as long as you mix up syntax with data model in your head. (Sort them out and things become easier.) One consequence of the insight that they are not the same is that you will no longer expect that the syntax you use in your XSLT is necessarily the same syntax that you will see in your result. Particularly, when it comes to namespaces, all you need to do is to ensure that the namespaces you want are on the elements where you want them (whether those elements are copied or created anew by your XSLT), and then let your serializer take care of the syntax. Since the epub namespace isn't anywhere in your source data, it is not copied through when you copy through all the other nodes in your source. (It is added, however, when you generate your attributes with names in that namespace. So declarations for it appear on elements with those attributes.) The solution is to add it everywhere. You can add it everywhere by modifying your identity template like this: <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.) 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.) I hope this helps -- Cheers, Wendell On Tue, Jun 24, 2014 at 4:30 AM, Peter West lists@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > I'm trying to convert EPUB2 files to EPUB3. In the course of that, I need to include some epub:type attributes. I also want to include a <!DOCTYPE html> declaration, although I have seen it argued that the declaration is not necessary. > > I have managed to get the DOCTYPE declaration to work by a method that has been described before in a number of places, and I have the epub:type attributes appearing on the relevant elements. However, the epub namespace is declared on every element, and I haven't been able to get it into the root element. How can I do this? > > My stylesheet starts like this: > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:xh="http://www.w3.org/1999/xhtml" > xmlns:epub="http://www.idpf.org/2007/ops" > exclude-result-prefixes="xs xh" > version="2.0"> > > <xsl:strip-space elements="*"/> > <xsl:output method="xhtml" /> > <xsl:template match="/"> > <xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text> > <xsl:apply-templates/> > </xsl:template> > > <xsl:template match="@*|node()"> > <xsl:copy> > <xsl:apply-templates select="@*|node()"/> > </xsl:copy> > </xsl:template> > > > > > Peter West > > "...he who eats my flesh and drinks my blood has eternal life, and I will raise him up at the last day." > -- Wendell Piez | http://www.wendellpiez.com XML | XSLT | electronic publishing Eat Your Vegetables _____oo_________o_o___ooooo____ooooooo_^
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Getting epub: namespace into , Peter West lists@xxx | Thread | Re: [xsl] Getting epub: namespace i, Abel Braaksma (Exsel |
Re: [xsl] node() function, Abel Braaksma (Exsel | Date | Re: [xsl] node() function, Wendell Piez wapiez@ |
Month |