RE: [xsl] reposting.append to a file in saxon. please help . still in office :)

Subject: RE: [xsl] reposting.append to a file in saxon. please help . still in office :)
From: "bryan" <bry@xxxxxxxxxx>
Date: Fri, 17 Jan 2003 10:07:29 +0100
>I wanted a solution so that i can append to a file without over writing
the
>previous contents. Dont know if  I would get help from anyone here
..want >to
>sort this out before going back to my home.
>I am still doing some R/D on this.

Okay, I had a discussion a long time ago about this problem in which my
solution was not a good one because it could lead to side effects, I
must confess I never did understand how it should lead to side effects
but I suppose I could look at the original discussion and maybe come to
some understanding. Unfortunately my time being extremely limited
nowadays I don't even have time for understanding anything. Here is an
example that should do what you want, it is not optimized, it is
hopefully free from possible side-effects, note that the attempt to so
free it has determined structure, am not going to do a lot of taking
advantage of 2.0 things as it's early in the morning here and I'm
drinking yesterday's coffee.



<xsl:stylesheet version='2.0'
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
>

<xsl:param name="append"/>
<xsl:param name="documents">
<documents>
<xsl:for-each select="/files/file">
<file name="{@name}">
<xsl:copy-of select="document(@name)"/>
</file>
</xsl:for-each>
</documents>
</xsl:param>
<xsl:template match="files">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="file">
<xsl:variable name="name" select="@name"/>
<xsl:result-document href="$name">
<document>
<xsl:copy-of select="$documents/documents/file[@name =
$name]/document/*">
<!--am assuming here that $append is a dom passed in as a parameter-->
<xsl:apply-templates select="$append"/>
</document>
</xsl:result-document>
</xsl:template>

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>

</xsl:template>

</xsl:stylesheet>


so I'm expecting with a document like this

<files>
<file name="some.xml"/>
</files>

and some.xml equals the following

<document>
<p>here's some text</p>
</document>

and $append equals

<append>howdy</append>


that some.xml after processing should equal 

<document>
<p>here's some text</p>
<append>howdy</append>
</document>

of course I haven't tested any of this, there can well be errors here as
I have just typed it, if there are some objections to this, as in it
could enable side effects I would like to have that explained and also
would like an explanation as to how one should append to a document, if
this is not a good way.

Now I'm gonna get some fresh coffee.




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


Current Thread