Hello!
I have a question regarding the behavior of
XSLProcessorContext.ouputToResultTree( ... ) in Xalan,v2.2.D6.
In v2.0.1, I was able to pass a Node to this function and have the node
be copied to the result tree (as expected). In the source code for
XSLProcessorContext, it appears that the only objects that can be sent
to the result tree are XObjects. Everything else is converted to a
String. So for instance, I can no longer create a ProcessingInstruction
and pass it to the result tree via this method since the PI is simply
converted to a String.
Is the intended approach to simply use XObjects in these cases? Or
should I be using the ResultTreeHandler directly to accomplish this
now? Does it make sense to allow copying of Node objects directly to
the result tree via outputToResultTree( ... )?
A similar behavior is noted when returning a NodeSet from an extension
element. Doing so simply results in the NodeSet being casted to a
String and sent to the output (ending up with something like
"org.apache.xpath.NodeSet@14d1e66" in the output).
I guess the main reason for asking these questions is to find out what
will be supported in the future versions of Xalan.
I've attached my example code to illustrate what I'm trying to say here.
<test:pi attr="{$foo}" /> is meant to show the differences in how I used
to get the PI's to the tree and how I think it should work now.
<test:nodeset /> returns a very simple NodeSet that I would expect to
show up as something like "<test>" in the output.
Thanks!
--Jason
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\\\|/// Jason Heddings ((
\\ ~ ~ // 303.272.5166 (x75166) C|~~|
(/ @ @ /) [EMAIL PROTECTED] `__'
~~oOOo~(_)~oOOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:test="ExtensionTest"
extension-element-prefixes="test"
>
<xsl:output method="html" encoding="ISO-8859-1" />
<xsl:template match="/">
<xsl:variable name="foo" select="/content" />
content:
<!--<test:pi attr="{$foo}" />-->
<test:nodeset />
</xsl:template>
</xsl:stylesheet>
import org.w3c.dom.* ;
import javax.xml.parsers.* ;
import javax.xml.transform.* ;
import org.apache.xalan.templates.* ;
import org.apache.xalan.extensions.* ;
import org.apache.xalan.transformer.* ;
import org.apache.xpath.* ;
import org.apache.xpath.objects.* ;
public class ExtensionTest {
private static ProcessingInstruction disableEscapePI ;
private static ProcessingInstruction enableEscapePI ;
private static Document elementFactory ;
static {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance( ) ;
try {
DocumentBuilder builder = factory.newDocumentBuilder( ) ;
elementFactory = builder.newDocument( ) ;
disableEscapePI =
elementFactory.createProcessingInstruction(
Result.PI_DISABLE_OUTPUT_ESCAPING , null ) ;
enableEscapePI =
elementFactory.createProcessingInstruction(
Result.PI_ENABLE_OUTPUT_ESCAPING , null ) ;
} catch ( javax.xml.parsers.ParserConfigurationException pce ) {
disableEscapePI = null ;
enableEscapePI = null ;
}
}
public void pi( XSLProcessorContext context , Element element )
throws javax.xml.transform.TransformerException {
Stylesheet style = context.getStylesheet( ) ;
TransformerImpl trans = context.getTransformer( ) ;
ResultTreeHandler rtree = trans.getResultTreeHandler( ) ;
String content = ( (ElemExtensionCall) element ).getAttribute(
"attr" , context.getContextNode( ) , context.getTransformer( ) ) ;
try {
context.outputToResultTree( style , "USING RESULT TREE:\n" ) ;
rtree.processingInstruction(
Result.PI_DISABLE_OUTPUT_ESCAPING , null ) ;
context.outputToResultTree( style , content ) ;
rtree.processingInstruction(
Result.PI_ENABLE_OUTPUT_ESCAPING , null ) ;
context.outputToResultTree( style , "\n\n" ) ;
} catch ( org.xml.sax.SAXException saxe ) {
} catch ( java.net.MalformedURLException mue ) {
} catch ( java.io.IOException ioe ) {
}
try {
context.outputToResultTree( style , "USING CONTEXT:\n" ) ;
context.outputToResultTree( style , disableEscapePI ) ;
context.outputToResultTree( style , content ) ;
context.outputToResultTree( style , enableEscapePI ) ;
context.outputToResultTree( style , "\n\n" ) ;
} catch ( java.net.MalformedURLException mue ) {
} catch ( java.io.IOException ioe ) {
}
}
public NodeSet nodeset( XSLProcessorContext context , Element element )
throws javax.xml.transform.TransformerException {
NodeSet nodeset = new NodeSet( ) ;
nodeset.addNode( elementFactory.createElement( "test" ) ) ;
return nodeset ;
}
}