Peter,

I do this a little different than you are attempting to do, but I think it will work.
I am assuming that myJava:myInput/MyForm is really like this


<xsl:template match="xdf:form">
          <myJava:myForm id="@id" />
</xsl:template>

<xsl:template match="xdf:input">
         <myJava:myInput name="@name" value="@value" foo="@foo" />
</xsl:template>

Where the XSLT is copying the data values into the extension element call.

If so, what you need to do is.
In myForm, output the form start element to the output tree. Then call this method

private void executeChildTemplates( XSLProcessorContext context, ElemExtensionCall elem ) throws TransformerException {
TransformerImpl transf = context.getTransformer();
transf.executeChildTemplates(elem, context.getContextNode(), context.getMode(), transf.getContentHandler());
}
Notice that is uses the current content handler..


executeChildTemplates should make the match to the next template which will trigger
the next extension element call. At this point, you are emitting SAX events into the
same output tree. So myForm can create is input start element, then also process the ChildTemplates, after ChildTemplates returns, then you want to close the elements that
you started and flush the output tree.


So if use the example I sent you before and replace the block of method calls that are outputting characters with the method above, it should just work.

Look at the Redirect extension element, there is some good code in there to use as an
example. At least that is where I started.

-JG


Peter Lerche wrote:

Hi John,

Thank you for your reply.

I implemented you sample code and it worked. However it did not address my main problem processing child nodes from within a extention function.

Example:

XML Source;
<xdf:form id="info">
        <xdf:input name="myBackendObj.name" foo="xxx"/>
</xdf:form>

Expected output
<form id="info" name="myBackendObj">
        <input name="myBackendObj.name" value="current value" foo="xxx">
</form>


XSLT

<xsl:template match="xdf:form">
          <myJava:myForm()/>
</xsl:template>

<xsl:template match="xdf:input">
         <myJava:myInput()/>
</xsl:template>


The myForm() function should do following.

form.createElementStart("form");
form.setAttributes();
executeChildTemplates()
form.createElementStart("form");


The creation of the "form" element is a doddel but the executeChildTemplates() is the problem




Any ideas

Peter






On Thursday 30 September 2004 00:31, John Gentilin wrote:


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]








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



Reply via email to