Getting Xerces to accept copy-of parameters

P

Patrik Carlsson

I have a problem using Xerces with a template for
a generic page-header getting a sub-tree as argument.
The same stylesheet is working flawlessly in IE and
Mozilla, though it would be nice to have a result-file
to work with too.

Here is an example (xerces only get a collapsed string through),
any suggestions or current bug-reports are welcome.

/ Patrik

My "paramtest.xml" :

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sendparam.xsl"?>
<rootnode>
<treenode>
<organization>The Apache Software Foundation</organization>
<street>1901 Munsey Drive</street>
<address>Forest Hill, MD 21050-2747</address>
<country>U.S.A</country>
</treenode>
<othernode>
othernode
</othernode>
</rootnode>

The stylesheet "sendparam.xsl" sending a node as parameter :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:eek:utput method="xml" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
encoding="ISO-8859-1" />

<xsl:include href="getparam.xsl"/>

<xsl:template match="rootnode">

<xsl:variable name="treecopy">
<xsl:copy-of select="treenode"/>
</xsl:variable>

<xsl:call-template name="testtemplate">
<xsl:with-param name="paramtree" select="$treecopy"/>
</xsl:call-template>

</xsl:template>
</xsl:stylesheet>

A generic stylesheet "getparam.xsl" using the parameter :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:eek:utput method="xml" indent="yes"
encoding="ISO-8859-1" />

<xsl:template name="testtemplate">
<xsl:param name="paramtree">no recipent</xsl:param>
<xsl:for-each select="$paramtree/treenode/*">
<b>
<xsl:value-of select="."/>
</b>
<br/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
 
D

Dave Bertoni

I have a problem using Xerces with a template for
a generic page-header getting a sub-tree as argument.
The same stylesheet is working flawlessly in IE and
Mozilla, though it would be nice to have a result-file
to work with too.

Here is an example (xerces only get a collapsed string through),
any suggestions or current bug-reports are welcome.

/ Patrik

You do mean you're using Xalan, right? Xerces is an XML parser, not
an XSLT processor.

....
The stylesheet "sendparam.xsl" sending a node as parameter :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:eek:utput method="xml" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
encoding="ISO-8859-1" />

<xsl:include href="getparam.xsl"/>

<xsl:template match="rootnode">

<xsl:variable name="treecopy">
<xsl:copy-of select="treenode"/>
</xsl:variable>

....

This variable is a result tree fragment, which has limitations in XSLT
1.0.
<xsl:call-template name="testtemplate">
<xsl:with-param name="paramtree" select="$treecopy"/>
</xsl:call-template>

</xsl:template>
</xsl:stylesheet>

A generic stylesheet "getparam.xsl" using the parameter :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:eek:utput method="xml" indent="yes"
encoding="ISO-8859-1" />

<xsl:template name="testtemplate">
<xsl:param name="paramtree">no recipent</xsl:param>
<xsl:for-each select="$paramtree/treenode/*">
<b>
<xsl:value-of select="."/>
</b>
<br/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

You are trying to use a result tree fragment as a node-set, which is
not allowed in XSLT 1.0. MSXSL 3.0 allows this, but 4.0 does not. I
don't know why Mozilla allows this, but that's a bug. Xalan is
correctly rejecting your stylesheet.

One way around this is to use a processor-specific extension to
convert a result tree fragment. Another choice is to use the EXSLT
node-set extension, which is more portable.

Dave
 
P

Patrik Carlsson

See the old post...
You are trying to use a result tree fragment as a node-set, which is
not allowed in XSLT 1.0. MSXSL 3.0 allows this, but 4.0 does not. I
don't know why Mozilla allows this, but that's a bug. Xalan is
correctly rejecting your stylesheet.

One way around this is to use a processor-specific extension to
convert a result tree fragment. Another choice is to use the EXSLT
node-set extension, which is more portable.

Dave

Thank's for the help,
Knowing the difference between node-sets and tree-fragments helped a lot.
Since my application was simple just sending the node without using
a variable solved my problem:

<xsl:with-param name="paramtree" select="/rootnode/treenode"/>

Then the parameter can be traversed as I wished

<xsl:for-each select="$paramtree/*">
<b><xsl:value-of select="."/></b><br/>
</xsl:for-each>

Cheers
Patrik
 

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,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top