xsl-list
[Top] [All Lists]

What's the correct way to output an element to the result tree

2004-09-29 05:20:33
Hi,

I was looking through this mailing-list trying to find an answer. However I 
found a question (posted in 2001) which addressed my problem but no answer. 
Therefore I am quoting the original question hoping somebody has the answer.

-QUOTE-
What's the correct way to output an element to the result tree from within
the code of an extension element (or function)?

As a dummy example, let's say I want to write a Javascript extension element
(using the Xalan-Java processor) to output a <p> tag, then process
the child elements of the context node, then output a </p> tag.  The code
I've got at the moment is

<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";;
                xmlns:lxslt="http://xml.apache.org/xslt";;
                xmlns:my="MyNamespace"
                extension-element-prefixes="my"
                version="1.0">
                
  <lxslt:component prefix="my" elements="para">
  <lxslt:script lang="javascript">
    <![CDATA[

      function para(xslContext,thisElement) {
        xslContext.outputToResultTree(xslContext.getStylesheet(),"<p>");
        
        xslTrans = xslContext.getTransformer();
        xslTrans.executeChildTemplates(thisElement,
           xslContext.getContextNode(),
           xslContext.getMode(),
           true
        );
        
        xslContext.outputToResultTree(xslContext.getStylesheet(),"</p>");
        
        return null;
      }
    ]]>
  </lxslt:script>
  </lxslt:component>

  <xsl:template match="/">
    <my:para>
      This is a paragraph.
    </my:para>
  </xsl:template>
</xsl:stylesheet>

Of course, this isn't right.  I don't want to output the text strings '<p>'
and '</p>'; I want to output an element node <p>.
-UNQUOTE-
-- 
Med venlig hilsen / Yours sincerely 
 
Peter
http://easyspeedy.com 
_______________________________________ 
European Dedicated Server Hosting 
Extremely low prices, secure, and reliable
Linux and BSD distributions only 
_______________________________________


<Prev in Thread] Current Thread [Next in Thread>