how to create a DocumentFragment in Xalan java extension function?

Discussion in 'XML' started by Arjen Haayman, Mar 1, 2004.

  1. 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>
    Arjen Haayman, Mar 1, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Bedford
    Replies:
    0
    Views:
    427
    Chris Bedford
    Aug 17, 2003
  2. Chris Bedford
    Replies:
    0
    Views:
    540
    Chris Bedford
    Aug 17, 2003
  3. Christian Schuhegger

    JARV and DocumentFragment validation

    Christian Schuhegger, Oct 20, 2003, in forum: XML
    Replies:
    0
    Views:
    385
    Christian Schuhegger
    Oct 20, 2003
  4. cvissy
    Replies:
    0
    Views:
    605
    cvissy
    Nov 16, 2004
  5. Mausam
    Replies:
    7
    Views:
    419
    Mausam
    Jan 18, 2012
Loading...

Share This Page