3 Replies - 2499 Views - Last Post: 27 January 2013 - 03:56 PM Rate Topic: -----

#1 jace427  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 7
  • Joined: 31-October 11

XSLT 1.0 Problem - Copying a child node in a duplicate record set

Posted 13 August 2012 - 01:04 PM

I have a need to write a transform that looks a duplicate record set, where one record contains a certain child node and one does not, and copies that child node to the one that doesn't. I am limited to XSLT 1.0 (I have no choice in this situation). In this example the unique identifier than defines a unique record is the "Name" element. The goal is to copy the "Status" element and remove all the records where "id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd" = 2. Thanks in advance... and for not asking WHY I need to do this, that's not the point. :)

Original XML:
<results>
	<row>
		<Name>Bunnies</Name>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>1</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Elephants</Name>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>1</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Tigers</Name>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>1</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Bunnies</Name>
		<Status>Fluffy</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>2</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Elephants</Name>
		<Status>Huge</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>2</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Tigers</Name>
		<Status>Mean</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>2</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
</results>



Desired Result:
<results>
	<row>
		<Name>Bunnies</Name>
		<Status>Fluffy</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>1</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Elephants</Name>
		<Status>Huge</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>1</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Tigers</Name>
		<Status>Mean</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>1</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Bunnies</Name>
		<Status>Fluffy</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>2</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Elephants</Name>
		<Status>Huge</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>2</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
	<row>
		<Name>Tigers</Name>
		<Status>Mean</Status>
		<id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>2</id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd>
	</row>
</results>



Is This A Good Question/Topic? 0
  • +

Replies To: XSLT 1.0 Problem - Copying a child node in a duplicate record set

#2 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 356
  • View blog
  • Posts: 785
  • Joined: 27-June 09

Re: XSLT 1.0 Problem - Copying a child node in a duplicate record set

Posted 13 August 2012 - 01:53 PM

This should store the appropriate status in a variable for your use.

<xsl:for-each select="row">
  <xsl:variable name="rowName" select="name" />
  <xsl:variable name="Sts" select="../row[name=$rowName and id-f340b6e4-fa71-55cf-d5f3-bc6ccda079fd='2']/Status" />
  <!--Build your result row here-->
</xsl:for-each>


This post has been edited by mojo666: 13 August 2012 - 02:41 PM

Was This Post Helpful? 0
  • +
  • -

#3 tl8lms  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-January 13

Re: XSLT 1.0 Problem - Copying a child node in a duplicate record set

Posted 25 January 2013 - 02:15 PM

Mqekligf Eexjg <a href="http://hoganitonline.info/">hogan scarpe</a> Iappnhbl Lejcqv http://hoganitonline.info/
Was This Post Helpful? 0
  • +
  • -

#4 zc4bov  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-January 13

Re: XSLT 1.0 Problem - Copying a child node in a duplicate record set

Posted 27 January 2013 - 03:56 PM

Ahhpgvn Moeedi <a href="http://hoganitonline.info/">hogan scarpe</a> Ahbhkd Jiqicn http://hoganitonline.info/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1