RE: [xsl] XSL and DOM

Subject: RE: [xsl] XSL and DOM
From: "Jonathan M. Sprinkle" <Jonathan.Sprinkle@xxxxxxxxxxxxxx>
Date: Tue, 10 Jun 2003 15:10:38 -0500
My apologies if something similar was posted, and I missed it.  :)

> >the changes should be done on the same tree instead of generating a
> >new
> tree
> 
> That's not how XSLT is defined to work.
> 
> I'm afraid the right answer would be to use an XPath engine to
> implement your own transform-in-place language.

Paramdeep,

I too am working on something like this (you can look for the hotly
debated and controversial "template match : node-set ..." thread).

I found that it is acceptable to generate a new file, but in addition to
the commands that manipulate the portion of your source tree, that you
copy in total the attributes and nodes that are not being modified.  For
example, 

        <xsl:template match="/">
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="@*|node()">
	<copy>
		<xsl:apply-templates select="@* | node()"/>
	</copy>
        </xsl:template>
        <xsl:template match="(the node you want to modify)">
	<!-- do modifications, then apply templates to all children -->
                <xsl:apply-templates/> 
        </xsl:template>

The only danger with this is that you,
 - must make modifications to attributes before you do anything to the
children (at least, this is how it seems to work for me)
 - must ensure that if you match a particular node to modify that any
conditions for its context are contained in the match, or that there is
a sort of "else" statement that will copy everything if these additional
contexts fail.
 - need to take care that you dn't modify the node AND copy it,
resulting in some very strange trees. :)

I am afraid that I can't help you with specifics, as these are going to
be related directly to your application.  However, I have found that
this is a "virtual" self-modification, and i have even succeeded at
keeping the filename the same before and after translation through
manipulation in my calling program (I am linking in Xalan for my CPP
files), so it is hidden from the caller.

Good luck,
Jonathan


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


Current Thread