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/07/07 19:17:40 UTC
[Xalan-J] rtf-to-nodeset extension and namespace problems
Hi,
I'm trying to do a *result tree fragment to nodeset* extension function fo
Xalan. Here is my source code:
public class FunctionTree extends Function
{
public XObject execute(XPath path, XPathSupport execContext, Node
context, int opPos, Vector args)
throws org.xml.sax.SAXException
{
if (args.size() == 0) return null;
else if (args.size() > 1) return null;
XObject arg = (XObject)args.elementAt(0);
if (XObject.CLASS_RTREEFRAG == arg.getType())
{
XRTreeFrag xrtf = (XRTreeFrag)arg;
return new XNodeSet(xrtf.convertToNodeset());
}
else return arg;
}
}
As you can see, it is very simple.
It looks like it works with a no-namespaces example:
<?xml version="1.0" encoding="UTF-8"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="core.xsl" type="text/xsl"?>
<foo>
<bar/>
<bar/>
<bar/>
<bar/>
<bar/>
</foo>
with the stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="foo">
<xsl:variable name="temp">
<xsl:apply-templates/>
</xsl:variable>
<foo>
<xsl:apply-templates select="tree($temp)"/>
</foo>
</xsl:template>
<xsl:template match="bar">
<toto titi="gato"/>
</xsl:template>
<xsl:template match="toto">
<prout bato="{@titi}"/>
</xsl:template>
</xsl:stylesheet>
i get:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<foo>
<prout bato="gato"></prout>
<prout bato="gato"></prout>
<prout bato="gato"></prout>
<prout bato="gato"></prout>
<prout bato="gato"></prout>
</foo>
<!-- This page was served from cache in 0 milliseconds by Cocoon 1.7.3 -->
But with a with-namespaces example:
<?xml version="1.0" encoding="UTF-8"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="core-with-ns.xsl" type="text/xsl"?>
<ns:foo xmlns:ns="http://fictive.org/schema">
<ns:bar/>
<ns:bar/>
<ns:bar/>
<ns:bar/>
<ns:bar/>
</ns:foo>
and the stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://fictive.org/schema"
>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="ns:foo">
<xsl:variable name="temp">
<temp>
<xsl:copy-of
select="ancestor-or-self::*/namespace::*"/>
<xsl:apply-templates/>
</temp>
</xsl:variable>
<ns:foo>
<xsl:apply-templates select="tree($temp)"/>
</ns:foo>
</xsl:template>
<xsl:template match="ns:bar">
<ns:toto titi="gato"/>
</xsl:template>
<xsl:template match="ns:toto">
<ns:prout bato="{@titi}"/>
</xsl:template>
</xsl:stylesheet>
i get the folowing exceptions:
java.lang.RuntimeException: xmlns:ns="http://fictive.org/schema"
Attribute child does not have an owner document element!
at
org.apache.xalan.xpath.xml.XMLParserLiaisonDefault.getParentOfNode(XMLParser
LiaisonDefault.java:1283)
at
org.apache.xalan.xpath.xml.XMLParserLiaisonDefault.getNamespaceOfNode(XMLPar
serLiaisonDefault.java:1149)
at
org.apache.xalan.xpath.SimpleNodeLocator.nodeTest(SimpleNodeLocator.java:175
0)
at
org.apache.xalan.xpath.SimpleNodeLocator.findAttributes(SimpleNodeLocator.ja
va:644)
at
org.apache.xalan.xpath.SimpleNodeLocator.step(SimpleNodeLocator.java:396)
at
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.java
:296)
at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
at org.apache.xalan.xpath.XPath.execute(XPath.java:1385)
at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
at org.apache.xalan.xpath.XPath.execute(XPath.java:274)
at
org.apache.xalan.xslt.AVTPartXPath.evaluate(AVTPartXPath.java:109)
at org.apache.xalan.xslt.AVT.evaluate(AVT.java:308)
at
org.apache.xalan.xslt.ElemLiteralResult.execute(ElemLiteralResult.java:223)
at
org.apache.xalan.xslt.ElemTemplateElement.executeChildren(ElemTemplateElemen
t.java:659)
at
org.apache.xalan.xslt.ElemTemplateElement.transformChild(ElemTemplateElement
.java:1194)
at
org.apache.xalan.xslt.ElemTemplateElement.transformSelectedChildren(ElemTemp
lateElement.java:957)
at
org.apache.xalan.xslt.ElemApplyTemplates.execute(ElemApplyTemplates.java:176
)
...
If i change:
<xsl:variable name="temp">
<xsl:apply-templates/>
</xsl:variable>
by:
<xsl:variable name="temp">
<temp>
<xsl:copy-of
select="ancestor-or-self::*/namespace::*"/>
<xsl:apply-templates/>
</temp>
</xsl:variable>
this now works. But not with more complex examples.
What am i missing ????
I've seen the posts of Juergen and al. that were speaking of a similar
extension for XalanC.
Should i clone nodes ? Does anyone has allready done this ?? Any hints ??
Thanks for you help.
Didier.