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

Changing and overwriting the structure of an existing

Subject: Changing and overwriting the structure of an existing XML document
From: Martin Casterud <casterud@xxxxxxxx>
Date: Tue, 24 Apr 2001 14:12:01 +0200 (CEST)
xsl overwriting attribute
*** Changing and overwriting the structure of an
existing XML document ***

Hi, been trying to solve this problem for quite some
time now... I have one XML file, main.xml, that among
other elements contains VARIABLE elements with the
attributes name and value:

<VARIABLE name="b" value="214" />

I also have an XML file called pool.xml that contains
references to these VARIABLE elements, structured like
this:

<POOL>
<VAR name="a" value="1" />
<VAR name="b" value="2" />
<VAR name="c" value="3" />
</POOL>

If I encounter a VARIABLE element in main.xml I want
to give the reference in pool.xml the value of the
"value attribute" encountered.

I have tried to solve this, but with no success. My
unsuccessful solution was a template "set" that was
called for each VARIABLE element [I know it's not the
neatest solution]:

<xsl:template name="set">

<xsl:param name="name" />
<xsl:param name="value" />

<xsl:variable name="temp">
<POOL>
<xsl:for-each select="document('pool.xml')/POOL/VAR">
<VAR>

<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>

<xsl:attribute name="value">
<xsl:choose>
<xsl:when test="@name = $name">
<xsl:value-of select="$value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@value" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</VAR>

</xsl:for-each>

</POOL>

</xsl:variable>

<xsl:document href="pool.xml">
<xsl:copy-of select="$temp" />
</xsl:document>

</xsl:template>

The problem seems to be that when I have encountered
the first VARIABLE element in main.xml and saved the
new structure in the variable "$temp" I want to
overwrite the old structure in pool.xml with the new
value in $temp. BUT, as the processor [I use SAXON] is
writing the content to pool.xml, it seems to read the
old values in parallel as it starts manipulating the
next VARIABLE element, instead of reading the new
values. Confusing, did any of you understand my
problem??

Is there any way to solve this problem with just XML
documents and XSLT?

Sincerely
Martin Casterud

_____________________________________________________
Do You Yahoo!?
Ditt_namn@xxxxxxxx - skaffa en gratis mailadress på http://mail.yahoo.se

 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.