Re: [xsl] Obtaining Graphic File Widths

Subject: Re: [xsl] Obtaining Graphic File Widths
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Jul 2006 16:31:02 -0400
Ryan,

At 04:13 PM 7/10/2006, you wrote:
I am trying to set up my stylesheet/FO so that it would be able to look at
any graphic files used an XML file and obtain the actual width of the image.
Is it possible to get the width value of a graphic file (we are using SVGs)
using a Java extension or by some other method? I have tired using the
document() function to call on the SVG (since it is an XML file after all)
and grab the width attribute, but apparently the document function only
works on files with a .xml extension.

That doesn't sound compliant. What processor is that? document() shouldn't care what the name of the file is, as long as it parses (and unless your SVG is broken, it does).

 I have also tried using the
ximg:getWidth function but didnt have much luck with that eithernot sure,
but this might be because I am not using the Docbook stylesheet. I was able
to plug everything into my styleheet but only got 0 as a return value for
the graphic width.

        <xsl:when test="function-available('ximg:getWidth')">
               <xsl:value-of select="ximg:getWidth(ximg:new($filename),
                                                $nominal.image.width)"/>
        </xsl:when>

I am currently using Xalan 2.7.0 with Antenna Houses XSLFormatter V3 for my
PDF output.

Extension functions almost by definition are not very portable.


You may be having trouble with document() since
the base URI of the call (the starting point of
its traversal) may not be where you think it is.

Try using document('path/to/x.svg',/) (note
second argument to the function) and making sure
that the path in 'path/to/x.svg' traverses relative to the source document.

document($arg1) with no $arg2 is supposed to
traverse the system relative to the stylesheet,
but your setup may not be handling this correctly.

Another way of going about this might be to run
your transforms outside AntennaHouse and then
giving it just the FO result to process (format).
This way the transformation phase is a bit easier
to manage, diagnose and correct.

Good luck,
Wendell

Current Thread