RE: [xsl] data structure in xslt?

Subject: RE: [xsl] data structure in xslt?
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 7 Oct 2002 17:02:03 -0400
[ 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

> 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

	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>

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

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.  


Tom P

 XSL-List info and archive:

Current Thread