You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Wendell Piez <wa...@mulberrytech.com> on 2005/04/19 21:41:29 UTC

Getting access to SVG image metrics [was RE: document() function in Saxon 8.3 under Cocoon 2.1.7]

Conal, Jörg, and any and all helpful Cocoonists --

I'm back again with Cocoon trying to get it to give me the dimensions of my 
SVG files. If you recall, I need these to calculate correct aspect ratios 
in an XSLT transform generating output that includes them by reference.

I've concluded I shouldn't rely on document() for this (which you recall is 
not working in Saxon 8.3 or 8.4; apparently the baseURI is not available to 
correctly traverse relative file system paths) but instead rely on 
Cocoon-native features. Friendlier for caching and all that.

XPathDirectoryGenerator is giving me some results, but still partial. In my 
sitemap.xmap I have

<map:match pattern="**svg-directory">
   <map:generate src="{1}" type="xpathdirectory">
     <map:parameter name="xpath" value="/*/@width | /*/@height"/>
     <map:parameter name="xmlFiles" value="\.svg$"/>
   </map:generate>
   <map:serialize type="xml" />
</map:match>

which gives me back, for http://localhost:8888/briarpatch/svg-directory 
(excerpted):

<dir:file name="homepage.svg" lastModified="1113007934000" date="4/8/05 
8:52 PM" size="5579">
   <dir:xpath query="/*/@width | /*/@height">7681024</dir:xpath>
</dir:file>
<dir:file name="testpage.svg" lastModified="1113090950000" date="4/9/05 
7:55 PM" size="2843">
   <dir:xpath query="/*/@width | /*/@height">7681024</dir:xpath>
</dir:file>
<dir:file name="westminster-c.svg" lastModified="1112913738000" 
date="4/7/05 6:42 PM" size="12227">
   <dir:xpath query="/*/@width | /*/@height">184872</dir:xpath>
</dir:file>

... which is fine as far as it goes, but not yet what I need (as you can see).

(I'd be thrilled if the effect here were simply to copy these attributes, 
as attributes, to the dir:file element (by default) or even to a copy of a 
subtree provided in the input. Would sitemap.xmap support the equivalent of 
XSLT LREs? (Think of that!) However, I'd settle for the values separable 
and in a known order.)

But when I change the 'xpath' parameter as so

<map:parameter name="xpath" value="concat(/*/@width, ' ', /*/@height)"/>

I get only

<dir:file name="homepage.svg" lastModified="1113007934000" date="4/8/05 
8:52 PM" size="5579">
   <dir:xpath query="concat(/*/@width, ' ', /*/@height)" />
</dir:file>
<dir:file name="testpage.svg" lastModified="1113090950000" date="4/9/05 
7:55 PM" size="2843">
   <dir:xpath query="concat(/*/@width, ' ', /*/@height)" />
</dir:file>
<dir:file name="westminster-c.svg" lastModified="1112913738000" 
date="4/7/05 6:42 PM" size="12227">
   <dir:xpath query="concat(/*/@width, ' ', /*/@height)" />
</dir:file>

... without the values.

This shortfall (unless a fix is available), plus the fact that I also need 
metrics for jpegs (which I can get using the image-directory generator), 
leads me to suppose that Conal's next suggestion might be the best:

>Otherwise, there's also a more long-winded but more flexible way, where you
>transform the result of the DirectoryGenerator to produce xi:include
>elements pointing at a pipeline which extracts image metrics from a file,
>and use the xinclude transformer to perform the inclusions, thereby calling
>that extraction pipeline once for each file.

I assume I can do the same with the result of an Image Directory generator, 
which (contrary to the docs) is listing all my files, not just images 
(though height and width are included with images).

But I need more details on how to do this. Can anyone direct me further or 
provide me an example? (In the meantime I'll be ferreting into the 
documentation.)

Alternatively, hints on how to get another approach to work would be welcome.

Given that SVGs are (sort of) images, maybe the Image Directory generator 
ought to report the dimensions of SVGs out of the box ... then I wouldn't 
even need any of the fancy stuff.

But I don't mind writing a bit of XSLT if it'll help get the job done.

Thanks again for the help,
Wendell

At 02:16 AM 4/10/2005, Conal wrote:
>Hi Wendell. I think you should look at the XPathDirectoryGenerator. This is
>a sub-class of the DirectoryGenerator which allows you to evaluate an XPath
>expression inside each document, perhaps something like
>"concat(/svg:svg/@width, ', ', /svg:svg/@height)"
>
>http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/generation/XPathDirec
>toryGenerator.html
>
>Otherwise, there's also a more long-winded but more flexible way, where you
>transform the result of the DirectoryGenerator to produce xi:include
>elements pointing at a pipeline which extracts image metrics from a file,
>and use the xinclude transformer to perform the inclusions, thereby calling
>that extraction pipeline once for each file.

___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_
     "Thus I make my own use of the telegraph, without consulting
      the directors, like the sparrows, which I perceive use it
      extensively for a perch." -- Thoreau 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org