]> granicus.if.org Git - docbook-dsssl/commitdiff
Cleaning and regularizing the generation of namespaced nodes for OPF, NCX, XHTML...
authorKeith Fahlgren <abdelazer@users.sourceforge.net>
Fri, 27 Mar 2009 01:59:46 +0000 (01:59 +0000)
committerKeith Fahlgren <abdelazer@users.sourceforge.net>
Fri, 27 Mar 2009 01:59:46 +0000 (01:59 +0000)
xsl/epub/bin/spec/epub_spec.rb
xsl/epub/docbook.xsl

index e4ea0f635539c428d9e917c5bf79704436864cd9..6ab69c952a5851b7ed3e6b8cbfc1013b3e967b5b 100755 (executable)
@@ -217,7 +217,7 @@ describe DocBook::Epub do
       success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}")
       raise "Could not unzip #{@css_epubfile}" unless success
       opf_files = Dir.glob(File.join(tmpdir, "**", "*.opf"))
-      opf_links = opf_files.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /<item [^>]*#{@css_file_base}/}
+      opf_links = opf_files.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /<(opf:item|item) [^>]*#{@css_file_base}/}
       opf_links.should_not be_empty
     rescue => e
       raise e
@@ -233,7 +233,7 @@ describe DocBook::Epub do
       success = system("unzip -q -d #{File.expand_path(tmpdir)} -o #{@css_epubfile}")
       raise "Could not unzip #{@css_epubfile}" unless success
       opf_files = Dir.glob(File.join(tmpdir, "**", "*.opf"))
-      opf_links = opf_files.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /<item [^>]*#{@embedded_font_file_base}/}
+      opf_links = opf_files.find_all {|opf_file| File.open(opf_file).readlines.to_s =~ /<(opf:item|item) [^>]*#{@embedded_font_file_base}/}
       opf_links.should_not be_empty
     rescue => e
       raise e
index 0c1c206000145e88f5ed16daf46d872773e09a07..151478a387f52b2d2153dfc20abb36071e196f13 100644 (file)
@@ -1,14 +1,21 @@
 <?xml version="1.0"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-  xmlns:ng="http://docbook.org/docbook-ng"
-  xmlns:dc="http://purl.org/dc/elements/1.1/"  
+<xsl:stylesheet 
   xmlns:db="http://docbook.org/ns/docbook"
+  xmlns:dc="http://purl.org/dc/elements/1.1/"  
   xmlns:exsl="http://exslt.org/common" 
+  xmlns:h="http://www.w3.org/1999/xhtml"
+  xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
+  xmlns:ng="http://docbook.org/docbook-ng"
+  xmlns:odfc="urn:oasis:names:tc:opendocument:xmlns:container"
+  xmlns:opf="http://www.idpf.org/2007/opf"
   xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xtext="xalan://com.nwalsh.xalan.Text"
-  version="1.0"
+
   extension-element-prefixes="stext xtext"
-  exclude-result-prefixes="exsl db ng dc stext xtext">
+  exclude-result-prefixes="exsl db dc h ncx ng opf odfc stext xtext"
+
+  version="1.0">
 
   <xsl:import href="../xhtml-1_1/docbook.xsl" />
   <xsl:import href="../xhtml-1_1/chunk-common.xsl" />
       <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
       <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
       <xsl:with-param name="content">
-        <xsl:element name="package">
-          <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+        <xsl:element name="opf:package">
           <xsl:attribute name="version">2.0</xsl:attribute>
           <xsl:attribute name="unique-identifier"> <xsl:value-of select="$package-id"/> </xsl:attribute>
 
-          <xsl:element name="metadata">
+          <xsl:element name="opf:metadata">
             <xsl:element name="dc:identifier">
               <xsl:attribute name="id"><xsl:value-of select="$package-id"/></xsl:attribute>
               <xsl:choose>
             </xsl:element>
 
             <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"> 
-              <xsl:element name="meta">
+              <xsl:element name="opf:meta">
                 <xsl:attribute name="name">cover</xsl:attribute>
                 <xsl:attribute name="content">
                   <xsl:value-of select="$epub.cover.image.id"/>
       <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
 
       <xsl:with-param name="content">
-        <xsl:element name="container">
-          <xsl:attribute name="xmlns">urn:oasis:names:tc:opendocument:xmlns:container</xsl:attribute>
+        <xsl:element name="odfc:container">
           <xsl:attribute name="version">1.0</xsl:attribute>
-          <xsl:element name="rootfiles">
-            <xsl:attribute name="xmlns">urn:oasis:names:tc:opendocument:xmlns:container</xsl:attribute>
-            <xsl:element name="rootfile">
-              <xsl:attribute name="xmlns">urn:oasis:names:tc:opendocument:xmlns:container</xsl:attribute>
+          <xsl:element name="odfc:rootfiles">
+            <xsl:element name="odfc:rootfile">
               <xsl:attribute name="full-path">
                 <!-- TODO: Figure out how to get this to work right with generation but also not be hardcoded -->
                 <xsl:value-of select="'OEBPS/content.opf'"/>
       <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
       <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
       <xsl:with-param name="content">
-        <xsl:element name="ncx">
+        <xsl:element name="ncx:ncx">
           <xsl:attribute name="version">2005-1</xsl:attribute>
-          <xsl:attribute name="xmlns">http://www.daisy.org/z3986/2005/ncx/</xsl:attribute>
 
             <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
             covers. We had to add one and we did so in conjunction with the IDPF and
             if the HTML cover item is marked linear="no" AND there is a guide item of
             type="cover" pointing to it AND there is a logical cover specified in a
             <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
-          <xsl:element name="head">
+          <xsl:element name="ncx:head">
             <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"> 
-              <xsl:element name="meta">
+              <xsl:element name="ncx:meta">
                 <xsl:attribute name="name">cover</xsl:attribute>
                 <xsl:attribute name="content">
                   <xsl:value-of select="$epub.cover.id"/>
               </xsl:element>
             </xsl:if>
             <xsl:if test="/*/*[contains(name(.), 'info')]/isbn"> 
-              <xsl:element name="meta">
+              <xsl:element name="ncx:meta">
                 <xsl:attribute name="name">dtb:uid</xsl:attribute>
                 <xsl:attribute name="content">
                   <xsl:text>isbn:</xsl:text>
             <!-- TODO: be nice to have a name="cover" here for .mobi-->
 
             <!-- TODO What are these hardcoded values? -->
-            <xsl:element name="meta">
+            <xsl:element name="ncx:meta">
               <xsl:attribute name="name">dtb:depth</xsl:attribute>
               <xsl:attribute name="content">-1</xsl:attribute>
             </xsl:element>
-            <xsl:element name="meta">
+            <xsl:element name="ncx:meta">
               <xsl:attribute name="name">dtb:totalPageCount</xsl:attribute>
               <xsl:attribute name="content">0</xsl:attribute>
             </xsl:element>
-            <xsl:element name="meta">
+            <xsl:element name="ncx:meta">
               <xsl:attribute name="name">dtb:maxPageNumber</xsl:attribute>
               <xsl:attribute name="content">0</xsl:attribute>
             </xsl:element>
                   <xsl:with-param name="object" select="key('id',$rootid)" />
                 </xsl:call-template>
               </xsl:variable>
-              <xsl:element name="docTitle">
-                <xsl:element name="text"><xsl:value-of select="normalize-space($title)" />  </xsl:element>
+              <xsl:element name="ncx:docTitle">
+                <xsl:element name="ncx:text"><xsl:value-of select="normalize-space($title)" />  </xsl:element>
               </xsl:element>
-              <xsl:element name="navMap">
+              <xsl:element name="ncx:navMap">
                 <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
               </xsl:element>
             </xsl:when>
                   <xsl:with-param name="object" select="/" />
                 </xsl:call-template>
               </xsl:variable>
-              <xsl:element name="docTitle">
-                <xsl:element name="text">
+              <xsl:element name="ncx:docTitle">
+                <xsl:element name="ncx:text">
                   <xsl:value-of select="normalize-space($title)" />
                 </xsl:element>
               </xsl:element>
-              <xsl:element name="navMap">
+              <xsl:element name="ncx:navMap">
                 <xsl:choose>
                   <xsl:when test="$root.is.a.chunk != '0'">
                     <xsl:apply-templates select="/*" mode="ncx" />
                                   preceding::index)"/>
     </xsl:variable>
 
-    <xsl:element name="navPoint">
-      <xsl:attribute name="xmlns">http://www.daisy.org/z3986/2005/ncx/</xsl:attribute>
+    <xsl:element name="ncx:navPoint">
       <xsl:attribute name="id">
         <xsl:value-of select="$id"/>
       </xsl:attribute>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:attribute>
-      <xsl:element name="navLabel">
-        <xsl:element name="text"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
+      <xsl:element name="ncx:navLabel">
+        <xsl:element name="ncx:text"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
       </xsl:element>
-      <xsl:element name="content">
+      <xsl:element name="ncx:content">
         <xsl:attribute name="src">
           <xsl:value-of select="$href"/>
         </xsl:attribute>
   <xsl:template name="opf.guide">
     <xsl:if test="contains($toc.params, 'toc') or 
                   /*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"> 
-      <xsl:element name="guide">
-        <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+      <xsl:element name="opf:guide">
         <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"> 
-          <xsl:element name="reference">
+          <xsl:element name="opf:reference">
             <xsl:attribute name="href">
               <!-- TODO: Figure out how to get this to work right with generation but also not be hardcoded -->
               <xsl:value-of select="'cover.html'"/>
         </xsl:if>  
 
         <xsl:if test="contains($toc.params, 'toc')">
-          <xsl:element name="reference">
+          <xsl:element name="opf:reference">
             <xsl:attribute name="href">
               <!-- TODO: Figure out how to get this to work right with generation but also not be hardcoded -->
               <xsl:call-template name="toc-href">
 
   <xsl:template name="opf.spine">
 
-    <xsl:element name="spine">
-      <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+    <xsl:element name="opf:spine">
       <xsl:attribute name="toc">
         <xsl:value-of select="$epub.ncx.toc.id"/>
       </xsl:attribute>
 
       <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"> 
-        <xsl:element name="itemref">
+        <xsl:element name="opf:itemref">
           <xsl:attribute name="idref">
             <xsl:value-of select="$epub.cover.id"/>
           </xsl:attribute>
 
 
       <xsl:if test="contains($toc.params, 'toc')">
-        <xsl:element name="itemref">
+        <xsl:element name="opf:itemref">
           <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
           <xsl:attribute name="linear">yes</xsl:attribute>
         </xsl:element>
     </xsl:variable>
 
     <xsl:if test="$is.chunk != 0">
-      <xsl:element name="itemref">
-        <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+      <xsl:element name="opf:itemref">
         <xsl:attribute name="idref">
           <xsl:value-of select="generate-id(.)"/>
         </xsl:attribute>
   </xsl:template>
 
   <xsl:template name="opf.manifest">
-    <xsl:element name="manifest">
-      <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+    <xsl:element name="opf:manifest">
       <!-- TODO: Figure out how to get this to work right with generation but also not be hardcoded -->
-      <xsl:element name="item">
+      <xsl:element name="opf:item">
         <xsl:attribute name="id"> <xsl:value-of select="$epub.ncx.toc.id"/> </xsl:attribute>
         <xsl:attribute name="media-type">application/x-dtbncx+xml</xsl:attribute>
         <xsl:attribute name="href"><xsl:value-of select="$epub.ncx.filename"/> </xsl:attribute>
       </xsl:element>
 
       <xsl:if test="contains($toc.params, 'toc')">
-        <xsl:element name="item">
+        <xsl:element name="opf:item">
           <xsl:attribute name="id"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
           <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
           <xsl:attribute name="href">
       </xsl:if>  
 
       <xsl:if test="$html.stylesheet != ''">
-        <xsl:element name="item">
-          <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+        <xsl:element name="opf:item">
           <xsl:attribute name="media-type">text/css</xsl:attribute>
           <xsl:attribute name="id">css</xsl:attribute>
           <xsl:attribute name="href"><xsl:value-of select="$html.stylesheet"/></xsl:attribute>
       </xsl:if>
 
       <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"> 
-        <xsl:element name="item">
-          <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+        <xsl:element name="opf:item">
           <xsl:attribute name="id"> <xsl:value-of select="$epub.cover.id"/> </xsl:attribute>
           <xsl:attribute name="href"> 
             <!-- TODO: Figure out how to get this to work right with generation but also not be hardcoded -->
       </xsl:if>  
 
      <xsl:if test="$epub.embedded.font != ''">
-        <xsl:element name="item">
-          <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+        <xsl:element name="opf:item">
           <xsl:attribute name="id">epub.embedded.font</xsl:attribute>
           <xsl:attribute name="href"><xsl:value-of select="$epub.embedded.font"/></xsl:attribute>
           <xsl:choose>
 
     <xsl:variable name="filename" select="concat($callout.graphics.path, $conum, $callout.graphics.extension)"/>
 
-    <xsl:element name="item">
-      <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+    <xsl:element name="opf:item">
       <xsl:attribute name="id"> <xsl:value-of select="concat(generate-id(.), 'callout', $conum)"/> </xsl:attribute>
       <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
       <xsl:attribute name="media-type">
       <!-- only do this if we're the first file to match -->
       <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
       <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
-        <xsl:element name="item">
-          <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+        <xsl:element name="opf:item">
           <xsl:attribute name="id"> 
             <xsl:choose>
               <xsl:when test="(ancestor::mediaobject[@role='cover'] or ancestor::cover) and (../@role='front-large' or count(ancestor::mediaobject/descendant::imageobject) = 1)">
     <!-- only do this if we're the first file to match -->
     <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
     <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
-      <xsl:element name="item">
-        <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+      <xsl:element name="opf:item">
         <xsl:attribute name="id"> 
           <xsl:choose>
             <xsl:when test="(ancestor::mediaobject[@role='cover'] or ancestor::cover) and (../@role='front-large' or count(ancestor::mediaobject/descendant::imageobject) = 1)">
     </xsl:variable>
 
     <xsl:if test="$is.chunk != 0">
-      <xsl:element name="item">
-        <xsl:attribute name="xmlns">http://www.idpf.org/2007/opf</xsl:attribute>
+      <xsl:element name="opf:item">
         <xsl:attribute name="id"> <xsl:value-of select="$id"/> </xsl:attribute>
         <xsl:attribute name="href"> <xsl:value-of select="$href"/> </xsl:attribute>
         <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
       <xsl:with-param name="indent" select="'yes'" />
       <xsl:with-param name="quiet" select="$chunk.quietly" />
       <xsl:with-param name="content">
-        <xsl:element name="html">
-          <xsl:attribute name="xmlns">http://www.w3.org/1999/xhtml</xsl:attribute>
-          <xsl:element name="head">
-            <xsl:element name="title">Cover</xsl:element>
-            <xsl:element name="style">
+        <xsl:element name="h:html">
+          <xsl:element name="h:head">
+            <xsl:element name="h:title">Cover</xsl:element>
+            <xsl:element name="h:style">
               <xsl:attribute name="type">text/css</xsl:attribute>
               <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
               <xsl:text> img { max-width: 100%; }</xsl:text>
             </xsl:element>
           </xsl:element>
-          <xsl:element name="body">
-            <xsl:element name="div">
+          <xsl:element name="h:body">
+            <xsl:element name="h:div">
               <xsl:attribute name="id">
                 <xsl:value-of select="$epub.cover.image.id"/>
               </xsl:attribute>