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

RE: copy single node once from one location to another

Subject: RE: copy single node once from one location to another
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Mon, 9 Sep 2002 09:23:21 +0100
xsl copy data
<xsl:variable name="data-nr" select="/mydoc/specials/data_nr"/>

<xsl:template match="a">
  <a>
  <xsl:copy-of select="@*"/>
  <xsl:copy-of select="node()"/>
  <xsl:if test="count(preceding-sibling::a)+1 = $data-text">
    <xsl:copy-of select="$data_nr/../data-text"/>
  </xsl:if>
</xsl:template>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Thomas Olausson
> Sent: 06 September 2002 22:46
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  copy single node once from one location to another
> 
> 
> 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
> 


 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.