Subject: [xsl] 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) |
*** 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Mad Parser Desease??, Daniel Veillard | Thread | [xsl] match values, Tanzila Mohammad |
Re: [xsl] how to use an xsd as an x, Jeni Tennison | Date | RE: [xsl] MSXML4, Robert Seber |
Month |