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

RE: data structure in xslt?

Subject: RE: data structure in xslt?
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 7 Oct 2002 17:02:03 -0400
data structure of tom
[ Zhiyong Hong]
> 
> I am using xslt for code generation from xml document. I need 
> to maintain a data structure to remember a list of special 
> nodes I have visited before. Is there any way in xslt which 
> can address this issue?
> 

The best way to address it is to re-think what you want to achieve (see
below).

> For example, I have following xml document:
> 
> <method name="getPerson">
> <returnType>Person</returnType>
> <params/>
> 
> <method name="setPerson">
> <returnType/>
> <params>
> <param type="Person" name="p"/>
> </params>
> 
> When I first get the node of Person type, I know I need to 
> include Person.h or whatever interface it is. But after that 
> I don't need to do that again. So I need to remember the type 
> I already include, and I think I need a datastructure(a hash, 
> list or tree will do).

With xslt transformations, it is better to think out what you want to
achieve first. Your description above is not really ***what** you want
to accomplish.    What you really want to do here is something like
this:

	If my sourcedocument has at least one of 
	( "getPerson" or  "setPerson") method, I
	want to put a Person.h statement at the top of the output.

With this this as the goal, you could write something like this:

<xsl:variable name='insert-person-header'
	select='count(//method[@getPerson]) +
count(//method[@setPerson]) > 0'/>
<xsl:if test='$insert-person-header'
#include &lt;Person.h>
</xsl:if>

You could invoke this from a template that processes the root of the xml
document, so that it would be invoked before the templates for the
methods.

In the templates that process your methods, you will not output anything
about Person.h, since that would have been output (or not) earlier in
the output.

There are many variations and possibilities for optimization, but this
may well be all you need.  

Cheers,

Tom P

 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.