You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Didier VILLEVALOIS <dv...@techmetrix.net> on 2000/06/29 17:15:17 UTC

document() function... [once more]

Hello everybody,

This makes now a long time that i try to use the document() function in a
XSL spec compliant manner.
In this i fail.

I just made an example (a zip is attached that you just got to put unzipped
in your ROOT dir)

Here is the XSL source:

------ style/import.xsl ------
<?xml version="1.0"?>
<xsl:transform version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="boop">
		<html>
			<body>
				<p><xsl:apply-templates/></p>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="file1">
		File1 method
		<xsl:copy-of select="document(@name)/bar"/>
	</xsl:template>
	
	<xsl:template match="file2">
		File2 method
		<xsl:copy-of select="."/>
		<xsl:copy-of select="document(@name, .)/bar"/>
	</xsl:template>
	
	<xsl:template match="file3">
		File3 method
		<xsl:copy-of select="@name"/>
		<xsl:copy-of select="document(@name, document(''))/bar"/>
	</xsl:template>
</xsl:transform>

Here are three tst file to test the three document inclusion method of my
xsl : 

------ test1.xml ------
<?xml version="1.0"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="style/import.xsl" type="text/xsl"?>
<boop>
	<file1 name="foo.xml"/>
</boop>

------ test2.xml ------
<?xml version="1.0"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="style/import.xsl" type="text/xsl"?>
<boop>
	<file2 name="foo.xml"/>
</boop>

------ test3.xml ------
<?xml version="1.0"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="style/import.xsl" type="text/xsl"?>
<boop>
	<file3 name="foo.xml"/>
</boop>

And the two foo files:
------ style/foo.xml ------
<?xml version="1.0"?>
<bar>
	From stylesheet dir
</bar>

------ style/foo.xml ------
<?xml version="1.0"?>
<bar>
	From xml dir
</bar>


Here are now the three outputs :
------ output for test1.xml ------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html><body><p>
        
                File1 method
                <bar>
        From stylesheet dir
</bar>
</p></body></html>

<!-- This page was served from cache in 0 milliseconds by Cocoon 1.7.4 -->

------ output for test2.xml ------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html><body><p>
        
                File2 method
                <file2 name="foo.xml"></file2>
</p></body></html>

<!-- This page was served from cache in 10 milliseconds by Cocoon 1.7.4 -->

WITH AN ADDITIONNAL ERROR IN THE TOMCAT WINDOW:

XSL Warning: Can not load requested doc: file:D:/tomcat/foo.xml

------ output for test3.xml ------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html><body><p>
        
                File3 method
                <bar name="foo.xml">
        From stylesheet dir
</bar>
</p></body></html>

<!-- This page was served from cache in 0 milliseconds by Cocoon 1.7.4 -->

So this means that:

- the first method gets the 'foo' document in the style directory instead of
the 'foo' in the test directory
- the second method tries to find a 'foo' document in the tomcat directory
(i.e. the owner document of the '.' node has no base directory which should
be the test dir)
- the third method gets the 'foo' document in the style directory which is
the normal behavior as described by the spec.

I found that the hashtable of open document, that is used to retrieve base
directory, does not contain the first parsed file (here the testX.xml file).
By adding it to the hashtable, i succeed in making method 2 working
SOMETIME.
For the first method, i can't understand.

Please help me. I can't make my framework without having a document()
function that works correctly.

Thank you very much!!!
Didier.