Joe,

Is this what you are looking for, see code below. I have been using the code to create
content in both the output tree and in variables. Although I have found that not all XSL
elements are created equal. i.e. If I use this code to output content into the ResultTree
or a Parameter it will work fine, but if I use similar code to populate an xsl:attribute it
will not work unless I wrapper the code in an xsl:copy statement. I sent an email to the
list because I wanted an interpretation of the spec before I entered a bug. As an example


This does not work
<xsl:element name="foo">
<xsl:attribute name="test">
  <myext:function />
</xsl:attribute>
</xsl:element>

but this does.
<xsl:element name="foo">
<xsl:attribute name="test">
   <xsl:copy> <myext:function /></xsl:copy>
</xsl:attribute>
</xsl:element>


This method creates an element, then just adds text to the element. You would probably need to walk your RTF making a copy of the RTF to the output.

I hacked a bunch of code out to make the example simpler hopefully not
too much :-)

HTH
-JG

public void element( XSLProcessorContext context, ElemExtensionCall elem ) throws javax.xml.transform.TransformerException
{
// Grab the name of out parameter.
String pname = elem.getAttribute("name");
if ((pname==null) || (pname.length() == 0)) return;


String value = "Element Value";
if (value == null) value = "";
try
{
SerializationHandler handler = context.getTransformer().getResultTreeHandler();


handler.startElement("", QName.getLocalPart(pname), pname, null);
if (buse_cdata == true) handler.startCDATA();
handler.characters(value.toCharArray(), 0, value.length());
if (buse_cdata == true) handler.endCDATA();


handler.endElement("", QName.getLocalPart(pname), pname);
handler.flushPending();
}
catch (SAXException se)
{
throw new TransformerException(se);
}



Peter Lerche wrote:

Hi Joe,

Thanks for your reply. However I just don't get it.

If I make my function return type "String" a string will be placed in the result tree. If the function return type is Node or DocumentFargment it returns nothing.

Calling myFunction in the xsl template should result in swapping the <my:para> with a <p> tag and place the <p> tag in the result tree.
All child elements of the <p> tag should be returned to the source tree for xslt processing.
But how......


<xsl:template match="my:para">
           <myJava:myFunction()/>
</xsl:template>

<xsl:template match="c1">
          Do something......
</xsl:template>

I have following XML doc.

<my:para>
        <a/>
        <b/>
        <c>
                <c1>
                        test
                </c1>
        <c>
</my:para>



A. this function will return NOTHING
public static Node myFunction(ExpressionContext context) {
        Node contextNode = context.getContextNode();
       Element element=contextNode.getOwnerDocument().createElement("p");
       return element;
}

A. this function will return the String
public static String myFunction(ExpressionContext context) {
       return "Hello";
}



Peter




On Wednesday 29 September 2004 20:58, Joseph Kesselman wrote:


I believe the answer was, and is, that extension elements can't return
content yet.

Extension _functions_ can. See the docs for information about what kinds of
values will be interpreted as Xalan node-sets when returned by an extension
function's implementation.

http://xml.apache.org/xalan-j/extensions.html

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







--
--------------------------------------
John Gentilin
Eye Catching Solutions Inc.
18314 Carlwyn Drive
Castro Valley CA 94546

   Contact Info
[EMAIL PROTECTED]
Ca Office 1-510-881-4821
NJ Office 1-732-422-4917



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to