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/07 23:27:04 UTC
document() function in Saxon 8.3 under Cocoon 2.1.7
Hi,
I've been messing with Cocoon 2.1.7 for a few days now. I like it a great
deal. Simple things do not have to be complicated.
Because my application really benefits from the draft XSLT 2.0, I've got
Saxon 8.3 wired in. It's doing very well. (Snappy!) But ... I've run into a
discrepancy which I have to believe is a Cocoon thing.
I'm calling the document() function very simply -- if a value $source-name
is supposed to be a reference to an SVG file, I'm querying it to get the
dimensions of the SVG (given as attributes on the document element) and
putting them onto a temporary tree:
<xsl:variable name="dimension-lookup">
<d>
<xsl:choose>
<xsl:when test="ends-with($source-name,'.svg')">
<xsl:attribute name="what">Hoo! got SVG!</xsl:attribute>
<xsl:for-each select="document($source-name,/)/*">
<xsl:copy-of select="@width | @height"/>
</xsl:for-each>
</xsl:when>
...
</xsl:choose>
</d>
</xsl:variable>
Outside Cocoon, this works -- when I copy this 'd' element to the output,
having provided a $source-name='westminster.svg' I get
<d width="872" height="184"/>
... which reflects, in fact, the correct values in westminster.svg.
But when I run it inside Cocoon, I just get a plain <d/>.
In my sitemap, in order to ensure I can read these SVGs, I have:
<map:match pattern="**.svg">
<map:generate src="{1}.svg"/>
<map:serialize type="svgxml"/>
</map:match>
... which appears to be sufficient to give me the SVG back when I provide
it to Cocoon directly in my browser.
Anyone have a clue as to what's going on? I figured this might be a FAQ,
except I'm using the latest-and-greatest. Google gives me only hints like
"using the document() function inside Cocoon isn't recommended".
I'd be very obliged to anyone who could suggest a solution or a clean
workaround.
Thanks!
Wendell
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: document() function in Saxon 8.3 under Cocoon 2.1.7
Posted by Wendell Piez <wa...@mulberrytech.com>.
Hi again,
Further researches into my problem have been revealing.
The logs do indeed reveal Saxon 8.3 is having trouble with document():
>net.sf.saxon.trans.DynamicError: java.io.FileNotFoundException:
>C:\bin\cocoon-2.1.7\westminster-c.svg (The system cannot find the file
>specified)
... it's looking in the wrong place, as the correct file would be at
C:\bin\cocoon-2.1.7\build\webapp\Briarpatch\westminster-c.svg
Is this a problem whose only resolution is on the Saxon side?
Alternatively, maybe I can pass a magic parameter into the transform to
provide the missing bit of the path.
On another front, I have now managed to get document() working under Xalan,
but get an error from XSLTC. I guess document() is inoperable there for its
own particular reasons? (I guess it makes sense.)
Given this, I have thought about handing the information I need into the
transform by aggregating it into the source. But I am reluctant to give
every source file the extra baggage of the entire list of images on the
chance it might need one or two of them.
In order of preference, I guess my options are:
* find a solution or setting for Saxon so it "just works"
* pass some parameter in to amend path so Saxon does not traverse from
Cocoon's root
* provide documents with a mini-directory listing possible images
with their dimensions
I'm sure this kind of thing has been dealt with before. Another solution
for me would be to force the user to maintain the catalog. But that's no
fun at all.
Is anyone tracking this on the Saxon list? ;->
Gratefully,
Wendell
At 03:18 AM 4/9/2005, you wrote:
>Wendell Piez wrote:
>>Yes. Further research has suggested that problems with it in the past
>>should have nothing to do with this case. The FAQ warns against
>>document() and offers intelligible reasons for avoiding it, but
>>apparently it is supposed to work.
>
>Well, in the 2.0.x series and early 2.1.x releases changes in content
>pulled in via document() indeed didn't cause invalidation of the
>cached pipeline result. Touch one of the sources of the generators
>in the pipeline, or the stylesheet itself in order to reset the
>cache and see whether it helps.
>
>In my experience, Saxon 7.3 also had the habit of logging NPEs
>from its EntityResolver and occasionally causing failures when
>using document() in Cocoon 2.1.5. I was not able to reproduce
>the problem consistently, and ultimately switched to pipeline
>aggregation and XInclude.
>
>J.Pietschmann
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Getting access to SVG image metrics [was RE: document()
function in Saxon 8.3 under Cocoon 2.1.7]
Posted by Wendell Piez <wa...@mulberrytech.com>.
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
RE: document() function in Saxon 8.3 under Cocoon 2.1.7
Posted by Wendell Piez <wa...@mulberrytech.com>.
Conal,
At 02:16 AM 4/10/2005, you 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
Thanks, this looks great, I'll have to try it out. It should do what's needful.
>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.
Yes, this is along the lines of what I was thinking about....
Thanks again, much to chew on.
Cheers,
Wendell
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
RE: document() function in Saxon 8.3 under Cocoon 2.1.7
Posted by Conal Tuohy <co...@paradise.net.nz>.
Wendell Piez wrote:
> If an image directory were to include width and height of SVGs as well as
> rasters, I'd be in business ... I guess here the caching issues have
> already been addressed. This suggests a solution would be a preprocess
that
> would generate a directory of available SVGs, which I could aggregate.
(But
> how to trigger it, and how to implement?)
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.
Cheers
Con
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: document() function in Saxon 8.3 under Cocoon 2.1.7
Posted by Wendell Piez <wa...@mulberrytech.com>.
Thanks JP for this illuminating information (even if I feel a bit like I'm
looking at the trees from the bottom of a swimming pool :-).
I will poke further and see what I can learn. In particular, the insight
that the problem is probably related to caching is useful.
A little more background as to what I'm trying to do. I want to use
document() to discern the dimensions of graphics. For rasters, I can get
this information out of an image directory, and I can see how I could wrap
this via pipeline aggregation and get access to the info this way. (I've
used document() successfully in other contexts for this, but can see how
aggregation is tighter here.)
For SVGs, however, the image directory gives me nothing, so I'd actually
like to query the SVG itself to determine the dimensions provided on its
/svg/@width and /svg/@height.
If a designer changes an SVG, I'd like the content that calls that SVG in
to update gracefully, which means querying it again. So yeah definitely, a
potential caching issue (now my head is starting to hurt). Maybe I will
have to introduce some restriction or requirement that an SVG can't be
altered without also touching the file(s) that call it in.
If an image directory were to include width and height of SVGs as well as
rasters, I'd be in business ... I guess here the caching issues have
already been addressed. This suggests a solution would be a preprocess that
would generate a directory of available SVGs, which I could aggregate. (But
how to trigger it, and how to implement?)
(Would it help to turn off caching, at least as an experiment?)
Anyhow, I can see this is deeper than I'd thought, so I am very grateful
for the help. Maybe there's already an elegant solution to the
reading-dimensions-of-SVGs problem, using Cocoon constructs of which I'm
still unaware to get me around document().
Cheers,
Wendell
At 03:18 AM 4/9/2005, you wrote:
>Wendell Piez wrote:
>>Yes. Further research has suggested that problems with it in the past
>>should have nothing to do with this case. The FAQ warns against
>>document() and offers intelligible reasons for avoiding it, but
>>apparently it is supposed to work.
>
>Well, in the 2.0.x series and early 2.1.x releases changes in content
>pulled in via document() indeed didn't cause invalidation of the
>cached pipeline result. Touch one of the sources of the generators
>in the pipeline, or the stylesheet itself in order to reset the
>cache and see whether it helps.
>
>In my experience, Saxon 7.3 also had the habit of logging NPEs
>from its EntityResolver and occasionally causing failures when
>using document() in Cocoon 2.1.5. I was not able to reproduce
>the problem consistently, and ultimately switched to pipeline
>aggregation and XInclude.
>
>J.Pietschmann
___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_
"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
Re: document() function in Saxon 8.3 under Cocoon 2.1.7
Posted by "J.Pietschmann" <j3...@yahoo.de>.
Wendell Piez wrote:
> Yes. Further research has suggested that problems with it in the past
> should have nothing to do with this case. The FAQ warns against
> document() and offers intelligible reasons for avoiding it, but
> apparently it is supposed to work.
Well, in the 2.0.x series and early 2.1.x releases changes in content
pulled in via document() indeed didn't cause invalidation of the
cached pipeline result. Touch one of the sources of the generators
in the pipeline, or the stylesheet itself in order to reset the
cache and see whether it helps.
In my experience, Saxon 7.3 also had the habit of logging NPEs
from its EntityResolver and occasionally causing failures when
using document() in Cocoon 2.1.5. I was not able to reproduce
the problem consistently, and ultimately switched to pipeline
aggregation and XInclude.
J.Pietschmann
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: document() function in Saxon 8.3 under Cocoon 2.1.7
Posted by Wendell Piez <wa...@mulberrytech.com>.
Hi Joerg,
At 01:34 PM 4/8/2005, you wrote:
>(It's really a long time since I heard of you the last time - must have been
>on the MulberryTech XSL list.)
Yep: "home territory" for me. :-)
> > Anyone have a clue as to what's going on? I figured this might be a FAQ,
> > except I'm using the latest-and-greatest. Google gives me only hints like
> > "using the document() function inside Cocoon isn't recommended".
>
>The reason for the hint is a caching issue IIRC. document() should work in
>principle.
Yes. Further research has suggested that problems with it in the past
should have nothing to do with this case. The FAQ warns against document()
and offers intelligible reasons for avoiding it, but apparently it is
supposed to work. I may simply have fallen between two upgrades (since
Saxon is also in flux).
> >From your sitemap snippet I guess you think document() path is resolved
>against sitemap, what's not done AFAIK.
That's good to know. I tried that only as a wild guess, but resolving
against the file system is preferable.
> This might already be the reason for
>the failure. You can switch to sitemap by using "cocoon:/" pseudo protocol.
>Otherwise the path should be resolved in file system by default.
I will look into this.
It has also been suggested to me that there could be a URI resolution
problem, which I might be able to debug, now there's a baseURI() function.
>Furthermore there should be a log entry when document() fails. But I don't
>know on which log level it logs.
That also gives me a place to dig.
Needless to say, I'll still be grateful for any help. Either I have to find
and fix the bug in my setup, or this will haunt XSLT 2.0 experimenters ...
my use case for document() is a legit one, I think, and there are others.
If anyone else out there is trying Saxon 8.3 and can duplicate this bug (or
not, demonstrating the bug is in my setup), that would also be useful info.
>Hope this helps,
It does, thanks!
Wendell
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: document() function in Saxon 8.3 under Cocoon 2.1.7
Posted by Jörg Heinicke <Jo...@gmx.de>.
Hello Wendell,
(It's really a long time since I heard of you the last time - must have been
on the MulberryTech XSL list.)
> Hi,
>
> I've been messing with Cocoon 2.1.7 for a few days now. I like it a great
> deal. Simple things do not have to be complicated.
>
> Because my application really benefits from the draft XSLT 2.0, I've got
> Saxon 8.3 wired in. It's doing very well. (Snappy!) But ... I've run into
> a
> discrepancy which I have to believe is a Cocoon thing.
>
> I'm calling the document() function very simply -- if a value $source-name
> is supposed to be a reference to an SVG file, I'm querying it to get the
> dimensions of the SVG (given as attributes on the document element) and
> putting them onto a temporary tree:
>
> <xsl:variable name="dimension-lookup">
> <d>
> <xsl:choose>
> <xsl:when test="ends-with($source-name,'.svg')">
> <xsl:attribute name="what">Hoo! got SVG!</xsl:attribute>
> <xsl:for-each select="document($source-name,/)/*">
> <xsl:copy-of select="@width | @height"/>
> </xsl:for-each>
> </xsl:when>
> ...
> </xsl:choose>
> </d>
> </xsl:variable>
>
> Outside Cocoon, this works -- when I copy this 'd' element to the output,
> having provided a $source-name='westminster.svg' I get
>
> <d width="872" height="184"/>
>
> ... which reflects, in fact, the correct values in westminster.svg.
>
> But when I run it inside Cocoon, I just get a plain <d/>.
>
> In my sitemap, in order to ensure I can read these SVGs, I have:
>
> <map:match pattern="**.svg">
> <map:generate src="{1}.svg"/>
> <map:serialize type="svgxml"/>
> </map:match>
>
> ... which appears to be sufficient to give me the SVG back when I provide
> it to Cocoon directly in my browser.
>
> Anyone have a clue as to what's going on? I figured this might be a FAQ,
> except I'm using the latest-and-greatest. Google gives me only hints like
> "using the document() function inside Cocoon isn't recommended".
The reason for the hint is a caching issue IIRC. document() should work in
principle.
>From your sitemap snippet I guess you think document() path is resolved
against sitemap, what's not done AFAIK. This might already be the reason for
the failure. You can switch to sitemap by using "cocoon:/" pseudo protocol.
Otherwise the path should be resolved in file system by default.
Furthermore there should be a log entry when document() fails. But I don't
know on which log level it logs.
Hope this helps,
Joerg
--
Sparen beginnt mit GMX DSL: http://www.gmx.net/de/go/dsl
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org