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

Re: creating and accessing element in the same stylesh

Subject: Re: creating and accessing element in the same stylesheet
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 16 Apr 2002 09:43:01 +0100
Re:  creating and accessing element in the same stylesh
Hi Charly,

> Does anyone have any idea how to create an element in a template and
> accessing it with another template within the same stylesheet . I
> have a generic template that takes a specific format so I need to
> reformat my data before calling the generic template .

Whenever you create an set of XML using XSLT (1.0), it forms a result
tree fragment. To apply templates to nodes, they need to be in a node
set. The majority of processors have an extension function that
enables you to convert from a result tree fragment to a node set so
that you can process the information in the result tree fragment.

So, first you need to store the result tree fragment in a variable:

  <xsl:variable name="formatted">
    <root>
      <xsl:for-each select="/report/account">
        <account name="{@id}" value="{sum(detail/@value)}" />
      </xsl:for-each>
    </root>
  </xsl:variable>

Then you need to convert that to a node set using an extension
function, and apply templates to the 'root' element:

  <xsl;apply-templates select="exsl:node-set($formatted)/root" />

The extension function that you use depends on what processor you're
using. For MSXML, for example, you should use msxsl:node-set(). You
need to declare the relevant namespace in the xsl:stylesheet element.
For example, to use exsl:node-set(), you should have:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:exsl="http://exslt.org/common"
                exclude-result-prefixes="exsl">
...
</xsl:stylesheet>

Come XSLT 2.0 this will all be easier because there won't be such a
thing as "result tree fragments".

By the way, there's nothing in your code as you currently have it that
means that you need to go through this extra step; if you can, you
should avoid it because it's pretty expensive for the processor to
create new node sets, and because using an extension function prevents
your stylesheet from being portable across processors.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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-2013 All Rights Reserved.