OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: RE: [docbook-apps] Cannot resolve imagedata element's fileref attribute using modular docbook and XInclude


Title: RE: [docbook-apps] Cannot resolve imagedata element's fileref attribute using modular docbook and XInclude

All,

Ben Guillon (creator/maintainer of DbLaTeX) replied to this issue on the DbLaTeX mailing list over on SourceForge.  He provided a patch and a customized stylesheet which corrects this issue.  I have re-attached them here and included instructions in the event that future people experience the same issue and find this thread - but not the other.

To get DbLaTeX to properly adjust the "fileref" attribute of an "imagedata" element, you can either patch the system-wide DbLaTeX stylesheets, or use a custom stylesheet.  Both the patch and stylesheet are attached to this email.

To patch the system-wide stylesheet do this:

  $ su 'Enter root password'
  # cp mediaobj.patch  /usr/share/xml/docbook/stylesheet/dblatex/
  # pushd /usr/share/xml/docbook/stylesheet/dblatex
  # patch -p1 < mediaobj.patch
  # popd
  # exit
  $ whoami (verify you are no longer root)

To use the custom stylesheet, build your DocBook file using the "-p" option such as:

  $ dblatex  -p relativeuri.xsl  my_docbook_file.xml

Best regards,
--mike

--
Michael Erickson
Director Software Products
LOGIC
(612) 436-5118 : desk
(612) 384-1584 : cell
http://www.logicpd.com



-----Original Message-----
From: Bob Stayton [mailto:bobs@sagehill.net]
Sent: Wed 10/14/2009 1:15 PM
To: Michael Erickson; docbook-apps@lists.oasis-open.org; docbook@lists.oasis-open.org
Subject: Re: [docbook-apps] Cannot resolve imagedata element's fileref attribute using modular docbook and XInclude

I'm not familiar enough with dblatex to tell you how to proceed.  Can dblatex run a customization layer?  If so, you could try putting the @fileref template in that, which should trigger the resolution of xml:base attributes for filerefs.  That assumes that the rest of the code is compatible, since several utility templates are called upon to resolve path information.

Bob Stayton
Sagehill Enterprises
bobs@sagehill.net



        ----- Original Message -----
        From: Michael Erickson <mailto:michael.erickson@logicpd.com
        To: Bob Stayton <mailto:bobs@sagehill.net>  ; docbook-apps@lists.oasis-open.org ; docbook@lists.oasis-open.org
        Sent: Wednesday, October 14, 2009 11:10 AM
        Subject: RE: [docbook-apps] Cannot resolve imagedata element's fileref attribute using modular docbook and XInclude


        Bob,
       
        Thank you *very* much for the reply.  There appears to be a difference between the way graphics are handled between DbLaTeX and DocBook XSL.
       
        I compared /usr/share/xml/docbook/stylesheet/dblatex/xsl/graphic.xsl and /usr/share/xml/docbook/stylesheet/nwalsh/fo/graphics.xsl.  The dblatex version does not contain <xsl:template match="@fileref">.
       
        The other templates you mention appear to be the same.
       
        So, now that we've (possibly) found the issue, what do you think would be the best way to proceed?  I don't want to start "hacking" on the dblatex stylesheets without some understanding about what I'm doing.  Is there an easy way to simply include the DocBook XSL Stylesheet fo/graphics.xsl in the dblatex one?
       
        Alternatively, is there an "DocBook-to-DocBook" transformation that I could pass to xsltproc which would resolve xml:base attributes - which I could then pass to dblatex?
       
        Something like:
       
        $ xsltproc -o tmp.xml fixup.xsl book.xml
        $ # tmp.xml now has all of the paths in attributes correct
       
        $ dblatex tmp.xml
       
        I've been looking for something like the above, but haven't found anything yet.
       
        The closest I've gotten is using xmllint to verify the document.  When I view the output of that, I can see xml:base added to sections and other elements, but not the fileref attributes.
       
       
       
       
        --
        Michael Erickson
        Director Software Products
        LOGIC
        (612) 436-5118 : desk
        (612) 384-1584 : cell
        http://www.logicpd.com
       
       
       
        -----Original Message-----
        From: Bob Stayton [mailto:bobs@sagehill.net]
        Sent: Wed 10/14/2009 12:41 PM
        To: Michael Erickson; docbook-apps@lists.oasis-open.org; docbook@lists.oasis-open.org
        Subject: Re: [docbook-apps] Cannot resolve imagedata element's fileref attribute using modular docbook and XInclude
       
        Hi Michael,
        Do you know if dblatex knows how to resolve xml:base attributes?  If not, then that is where it is going wrong.
       
        When XInclude pulls in content from another directory, the XInclude processor inserts an xml:base attribute indicating the new directory.  That sort of stores a "change-of-directory" in the resolved XML content, so that relative paths (like yours) in the included content can be resolved downstream.  When the DocBook XSL stylesheets encounter a relative path in a fileref, they look for xml:base attributes and reconstruct any fileref path to resolve any xml:base attributes from all its ancestor elements.  If dblatex does not do that xml:base resolution, then the filerefs are passed through without change and lack the directory fixups.
       
        The relevant templates in DocBook XSL include:
       
        in fo/graphics.xsl:
          <xsl:template match="@fileref">
       
        in common/common.xsl:
          <xsl:template name="relative-uri">
          <xsl:template name="xml.base.dirs">
       
        Bob Stayton
        Sagehill Enterprises
        bobs@sagehill.net
       
       
       
                ----- Original Message -----
                From: Michael Erickson <mailto:michael.erickson@logicpd.com>
                To: docbook-apps@lists.oasis-open.org ; docbook@lists.oasis-open.org
                Sent: Wednesday, October 14, 2009 9:42 AM
                Subject: [docbook-apps] Cannot resolve imagedata element's fileref attribute using modular docbook and XInclude
       
       
                Hello all,
              
                I've posted the question below on the DbLaTeX mailing list, but I have a suspicion that my problem might be solved if I had a better understanding of XSL, XInclude, and using xsltproc.
              
                I would greatly appreciate any advice you might provide.
              
                Basic information:
                ------------------
                * Debian 5.0 "Lenny" host machine, all packages up-to-date
                * Validating against DocBook XML V4.5 DTD
                * dblatex version 0.2.9-3
                * $ latex --version
                pdfTeX using libpoppler 3.141592-1.40.3-2.2 (Web2C 7.5.6)
                kpathsea version 3.5.6
                    ...
                Compiled with libpng 1.2.27; using libpng 1.2.27
                Compiled with zlib 1.2.3.3; using zlib 1.2.3.3
                Compiled with libpoppler version 3.00
              
                * $ xsltproc --version
                Using libxml 20632, libxslt 10124 and libexslt 813
                xsltproc was compiled against libxml 20632, libxslt 10124 and libexslt 813
                libxslt 10124 was compiled against libxml 20632
                libexslt 813 was compiled against libxml 20632
              
              
                Problem:
                --------
                I'm having trouble getting dblatex to locate images.  I believe that the trouble lies someplace with xsltproc not expanding the "fileref" attribute using xml:path.  WARNING, I am *not* an XML or DocBook expert, so you should take any of my suspicions with a large grain of salt - and you may feel free to laugh should I say something that makes no sense :-)
              
                My directory structure looks like:
              
                book/
                ____| main.xml
                ____| appendix/
                ______________|appendix.xml
                ______________| foo/
                ___________________| foo.xml
                ___________________| images/
                ___________________________|*.png
              
                Book/main.xml uses XInclude to insert book/appendix/appendix.xml, which in turn uses XInclude to insert book/appendix/foo/foo.xml.  Book/appendix/foo/foo.xml contains elements such as:
              
                <mediaobject>
                  <imageobject>
                    <imagedata fileref="images/image_1.png" format="PNG" />
                  </imageobject>
                </mediaobject>
              
                If I enter the book/appendix/foo/ directory and execute:
                    $ dblatex foo.xml
                I have no problems.  Foo.pdf is created, and includes the images I expect it to.
              
                If I am anywhere above the "foo" directory, dblatex reports "Image 'images/image_1.png' not found" and the resultant PDF file does not include the images.
              
                What I've Tried:
                ----------------
                I can sucessfully use xsltproc to create HTML and "chunked" HTML files, as long as I pass the following parameters to it:
              
                  --xinclude
                  --param keep.relative.image.uris 0
              
                I've reviewed the XSL Parameters section (5.1) of the DocBook to LaTeX Publishing User Manual for something similar to "keep.relative.image.uris", but have been unsuccesfull.
              
                I've searched and grep'ed through the /usr/share/xml/docbook/stylesheet/dblatex files - but didn't see anything that jumped out at me (admittedly, they are out of my comfort zone).
              
                I've looked into trying to use xmllint or xlstproc to generate an intermediate XML file with completely resovled path names, so I could pipe that to dblatex, but haven't had any luck coming up with the proper XSL file or parameter combination.
              
                I've tried using the "-I" option to point dblatex at additional directories to search for "figures."  I also wrapped some of the <mediaobject> elements in figures - but that didn't seem to make a difference.
              
                I *have* confirmed that setting the fileref attribute to an absolute pathname *does* work.
              
                I've googled a ton and reviewed the dblatex mailing list on SourceForge.  Since I've come up empty, and I can't believe that nobody else has ever structured a document the why I have, my intuition tells me that I am missing something completely obvious.
              
                Can anyone help me understand what is happening and how to fix it?
              
                Best regards,
                --mike
              
                --
                Michael Erickson
                Director Software Products
                LOGIC
                (612) 436-5118 : desk
                (612) 384-1584 : cell
                http://www.logicpd.com
              
              
              
       
       
       



relativeuri.xsl

diff -r b3e763f2ff99 xsl/classsynopsis.xsl
--- a/xsl/classsynopsis.xsl	Thu Oct 15 01:02:11 2009 +0200
+++ b/xsl/classsynopsis.xsl	Thu Oct 15 01:02:16 2009 +0200
@@ -162,18 +162,6 @@
   <xsl:apply-templates mode="java"/>
 </xsl:template>
 
-<xsl:template name="copy-string">
-  <xsl:param name="string"/>
-  <xsl:param name="count" select="'1'"/>
-  <xsl:value-of select="$string"/>
-  <xsl:if test="$count &gt; 1">
-    <xsl:call-template name="copy-string">
-      <xsl:with-param name="string" select="$string"/>
-      <xsl:with-param name="count" select="$count - 1"/>
-    </xsl:call-template>
-  </xsl:if>
-</xsl:template>
-
 <xsl:template match="methodparam" mode="java">
   <!-- PARAM: indent := 0 -->
   <xsl:param name="indent">0</xsl:param>
diff -r b3e763f2ff99 xsl/common/lib.xsl
--- a/xsl/common/lib.xsl	Thu Oct 15 01:02:11 2009 +0200
+++ b/xsl/common/lib.xsl	Thu Oct 15 01:02:16 2009 +0200
@@ -73,4 +73,71 @@
   </xsl:choose>
 </xsl:template>
 
+<xsl:template name="count.uri.path.depth">
+  <xsl:param name="filename" select="''"/>
+  <xsl:param name="count" select="0"/>
+
+  <xsl:choose>
+    <xsl:when test="contains($filename, '/')">
+      <xsl:call-template name="count.uri.path.depth">
+        <xsl:with-param name="filename"
+                        select="substring-after($filename, '/')"/>
+        <xsl:with-param name="count" select="$count + 1"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$count"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="trim.common.uri.paths">
+  <xsl:param name="uriA" select="''"/>
+  <xsl:param name="uriB" select="''"/>
+  <xsl:param name="return" select="'A'"/>
+
+  <xsl:choose>
+    <xsl:when test="contains($uriA, '/') and contains($uriB, '/')                     and substring-before($uriA, '/') = substring-before($uriB, '/')">
+      <xsl:call-template name="trim.common.uri.paths">
+        <xsl:with-param name="uriA" select="substring-after($uriA, '/')"/>
+        <xsl:with-param name="uriB" select="substring-after($uriB, '/')"/>
+        <xsl:with-param name="return" select="$return"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:choose>
+        <xsl:when test="$return = 'A'">
+          <xsl:value-of select="$uriA"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="$uriB"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="copy-string">
+  <!-- returns 'count' copies of 'string' -->
+  <xsl:param name="string"/>
+  <xsl:param name="count" select="0"/>
+  <xsl:param name="result"/>
+
+  <xsl:choose>
+    <xsl:when test="$count&gt;0">
+      <xsl:call-template name="copy-string">
+        <xsl:with-param name="string" select="$string"/>
+        <xsl:with-param name="count" select="$count - 1"/>
+        <xsl:with-param name="result">
+          <xsl:value-of select="$result"/>
+          <xsl:value-of select="$string"/>
+        </xsl:with-param>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$result"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 </xsl:stylesheet>
diff -r b3e763f2ff99 xsl/mediaobject.xsl
--- a/xsl/mediaobject.xsl	Thu Oct 15 01:02:11 2009 +0200
+++ b/xsl/mediaobject.xsl	Thu Oct 15 01:02:16 2009 +0200
@@ -10,6 +10,7 @@
 <xsl:param name="imagedata.default.scale">pagebound</xsl:param>
 <xsl:param name="imagedata.file.check">1</xsl:param>
 <xsl:param name="imagedata.boxed">0</xsl:param>
+<xsl:param name="keep.relative.image.uris" select="0"/>
 
 
 <!-- Simple mediaobject selection using @role -->
@@ -241,6 +242,8 @@
   </xsl:if>
 </xsl:template>
 
+<!-- ==================================================================== -->
+
 <!-- Image filename to use -->
 <xsl:template match="imagedata|graphic|inlinegraphic" mode="filename.get">
   <xsl:choose>
@@ -248,10 +251,32 @@
     <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
   </xsl:when>
   <xsl:when test="@fileref">
-    <xsl:value-of select="@fileref"/>
-  </xsl:when>
-  </xsl:choose>
-</xsl:template>
+    <xsl:apply-templates select="@fileref"/>
+  </xsl:when>
+  </xsl:choose>
+</xsl:template>
+
+<!-- Resolve xml:base attributes (taken from the DocBook Project) -->
+<xsl:template match="@fileref">
+  <!-- need a check for absolute urls -->
+  <xsl:choose>
+    <xsl:when test="contains(., ':') or starts-with(.,'/')">
+      <!-- it has a uri scheme or starts with '/', so it is an absolute uri -->
+      <xsl:value-of select="."/>
+    </xsl:when>
+    <xsl:when test="$keep.relative.image.uris != 0">
+      <!-- leave it alone -->
+      <xsl:value-of select="."/>
+    </xsl:when>
+    <xsl:otherwise>
+      <!-- its a relative uri -->
+      <xsl:call-template name="relative-uri">
+      </xsl:call-template>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- ==================================================================== -->
 
 <!-- Process an imagedata -->
 


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]