A
Arjen Haayman
Hello,
I'm using Xalan and have written Java classes as extension functions.
According the documentation the return value of an extension function
can be a Result tree fragment: (== org.w3c.doc.DocumentFragment)
Now I can't figure out how to create an empty DocumentFragment from a
Java class that has been created in an XSL stylesheet
This is what I have so far:
public Object toSVG( ExpressionContext context)
{
Object retval;
try
{
Node node = context.getContextNode();
Document doc = node.getOwnerDocument();
DocumentFragment fragment = doc.createDocumentFragment();
Element text = doc.createElement( "text");
text.setPrefix( "svg");
text.setAttribute( "font-size", "2");
text.setAttribute( "transform", this.Transform());
text.setAttribute( "x", Double.toString( this.X()));
text.setAttribute( "y", Double.toString( this.Y()));
fragment.appendChild( text);
fragment.appendChild( bijpijling);
retval = fragment;
}
catch( DOMException e)
{
String error = Integer.toString( e.code);
Debug.Msg( 10, "error: " + error);
retval = error;
}
return( retval);
}
example usage (simplified)
<xsl:variable name="Tekst" select="map:TText.new( "aText")/>
<svg:a xlink:href="{$url}">
<xsl:for-each select="map:toSVG( $Tekst)">
<xsl:copy-of select="." />
</xsl:for-each>
</svg:a>
I'm using Xalan and have written Java classes as extension functions.
According the documentation the return value of an extension function
can be a Result tree fragment: (== org.w3c.doc.DocumentFragment)
Now I can't figure out how to create an empty DocumentFragment from a
Java class that has been created in an XSL stylesheet
This is what I have so far:
public Object toSVG( ExpressionContext context)
{
Object retval;
try
{
Node node = context.getContextNode();
Document doc = node.getOwnerDocument();
DocumentFragment fragment = doc.createDocumentFragment();
Element text = doc.createElement( "text");
text.setPrefix( "svg");
text.setAttribute( "font-size", "2");
text.setAttribute( "transform", this.Transform());
text.setAttribute( "x", Double.toString( this.X()));
text.setAttribute( "y", Double.toString( this.Y()));
fragment.appendChild( text);
fragment.appendChild( bijpijling);
retval = fragment;
}
catch( DOMException e)
{
String error = Integer.toString( e.code);
Debug.Msg( 10, "error: " + error);
retval = error;
}
return( retval);
}
example usage (simplified)
<xsl:variable name="Tekst" select="map:TText.new( "aText")/>
<svg:a xlink:href="{$url}">
<xsl:for-each select="map:toSVG( $Tekst)">
<xsl:copy-of select="." />
</xsl:for-each>
</svg:a>