Re: Newbie: How to write a stylesheet that preserves the input tree

Subject: Re: Newbie: How to write a stylesheet that preserves the input tree
From: Francois Belanger <francois@xxxxxxxxxxx>
Date: Thu, 10 Dec 98 14:00:04 -0500
(I did not get any answer to this but found it by looking at XT source. 
Tought some members would be interested.)

Francois Belanger wrote on 02/12/98 10h45:

>Using the current XSL Draft as well as James Clark XT, I'm trying to 
>preserve the attributes and node names of the input XML file nodes while 
>modifying order or adding new attributes.
>
>In other words, how can one write an XSL stylesheet that outputs the 
>exact same XML as the input file? Part of the problem is getting the node 
>name (xsl:nodeName is not within the current draft) 

in XT, you can use name(pattern) to access a node name. So if, for 
example, you need to know the immediate ancestor name of any "field" 
nodes within "page", this template: 

<xsl:template match="page//field">
    My parent name is <xsl:value-of expr="name(..)"/>
</xsl:template>
</xsl:stylesheet>

will let you know.

>and iterate through 
>it's attributes list.

I did not find out the equivelent of "@*" (which means all attributes in 
MS-XSL ;-) but there's a copy that does preserve the source node. This 
stylesheet will give the exact same tree as the input (useful as a 
default template within a stylesheet that output XML):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";>
<xsl:template match="/ | *">
<xsl:copy><xsl:process-children/></xsl:copy>
</xsl:template>
</xsl:stylesheet>

Hope this helps users of XT,  many thanks to James Clark! Feel free to 
correct me if my description is incorrect or let us know of any further 
features not part of the current draft.




Francois Belanger
Sitepak, Bringing Internet Business into Focus
http://www.sitepak.com



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


Current Thread