cocoon and document() function

G

Gerald Aichholzer

Hi NG,

I have the following xml-file (simplified):

<?xml version="1.0" encoding="ISO-8859-1"?>
<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0">
<dir:file name="cook0002.xml">
</dir:directory>

and the following xsl-file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dir="http://apache.org/cocoon/directory/2.0">

<xsl:template match="dir:directory">
<xsl:element name="demos">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="dir:file">
<xsl:element name="demo">
<xsl:element name="file">
<xsl:value-of select="@name"/>
</xsl:element>
<xsl:element name="symbol">
<xsl:value-of select="document(@name)/document/title"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

the output should be:

<?xml version="1.0" encoding="UTF-16"?>
<demos>
<demo>
<file>cook0002.xml</file>
<symbol>Wiener Schnitzel</symbol>
</demo>
</demos>

It works with Xselerator, but cocoon 2.1 gives me only the
following output:

<?xml version="1.0" encoding="UTF-16"?>
<demos>
<demo>
<file>cook0002.xml</file>
<symbol/>
</demo>
</demos>

Any hints for solving my problem?

Thanx in advance,
Gerald
 
B

Ben Edgington

Gerald Aichholzer said:
I have the following xml-file (simplified):

<?xml version="1.0" encoding="ISO-8859-1"?>
<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0">
<dir:file name="cook0002.xml">
</dir:directory>

Too simplified. Your dir:file element is not closed.
and the following xsl-file:
<xsl:value-of select="document(@name)/document/title"/>

This will look for a file called "cook0002.xml" which you don't show
us. If I create that file with these contents in the same directory as
my xslt file:
<document>
<title>Wiener Schnitzel</title>
</document>

then with both sablotron and xsltproc I get the result you desire.

Perhaps cocoon can't find the file cook0002.xml. In that case
xsltproc generates an empty tag and sablotron throws an error. Either
is allowed according to the W3C XSLT 1.0 Rec.

Ben
 
G

Gerald Aichholzer

Too simplified. Your dir:file element is not closed.



This will look for a file called "cook0002.xml" which you don't show
us. If I create that file with these contents in the same directory as
my xslt file:
<document>
<title>Wiener Schnitzel</title>
</document>

then with both sablotron and xsltproc I get the result you desire.

Perhaps cocoon can't find the file cook0002.xml. In that case
xsltproc generates an empty tag and sablotron throws an error. Either
is allowed according to the W3C XSLT 1.0 Rec.

That's exactly the problem - the file looks like in your example.
Cocoon's default path for looking for "cook0002.xml" wasn't where
I have expected it to be.

Anyway I have found out in the FAQ that it is not recommended to
use the document() function with cocoon. Right now I'm trying to
find out more about Xinclude and Xpointer which is suggested as
an alternative.

thanx,
Gerald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top