Subject: copy single node once from one location to another
From: Thomas Olausson <thomas.olausson@xxxxxxx>
Date: Fri, 06 Sep 2002 23:46:21 +0200
|
My XML file is being fed to an external system, which I don't have control of.
It adds a "specials"-tag at the end like this: (hardcoded)
<mydoc>
<a id="ABC">
<data>100</data>
<data>101</data>
</a>
<a id="DEF">
<data>200</data>
<data>201</data>
</a>
<specials>
<data_nr>2</data_nr>
<data_text>300</data_text>
</specials>
</mydoc>
I'd like to write a XSLT that moves the data_text to the corresponding index of "a", expressed in data_nr.
In the above case, /mydoc/a[2]
In the above example, I'd like the output to be
<mydoc>
<a id="ABC">
<data>100</data>
<data>101</data>
</a>
<a id="DEF">
<data>200</data>
<data>201</data>
<data>300</data>
</a>
<specials>
<data_nr>2</data_nr>
<data_text>300</data_text>
</specials>
</mydoc>
I just copied the 300-data to the 2nd 'a', because data_nr was 2.
I know which fields to copy from, and I don't need any error checking (in case there are only one a , but data_nr=2 would never happen)
I can't change the external system, and in XSLT, I haven't figured out to copy the line once. My XSLTs copies them one for every data item, even if I match correctly.
/Thomas
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|