[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to output an element from within an extension elem

Subject: How to output an element from within an extension element?
From: Michael Ody <Michael.Ody@xxxxxxxxxxxx>
Date: Mon, 17 Sep 2001 09:36:09 +0100
javascript getstylesheet
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>, but I haven't been able to
find any documentation or examples which mention this kind of thing.  (In
fact, I only found out about the .executeChildTemplates method by looking in
the source code for <xalan:write>!  Where *should* I look for a guide to
neat things I can do in Javascript extension elements/functions?)

Second question: Let's say I put the xsl:component and xsl:script stuff
shown above in a separate stylesheet, and then include or import this into
my main stylesheet.  Will the main stylesheet *and any other stylesheets
included/imported by it* be able to 'see' the definition of <my:para>?

All help appreciated,

Mike.

---
Signal Computing Ltd.       20 Nugent Road, The Surrey Research Park,
http://www.signal.co.uk     Guildford, Surrey GU2 7DF, UK
Tel: +44(0)1483 579900    Fax: +44(0)1483 562836
Registered in London, No. 1672944

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.