Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2013, 06:54 AM
Authorized User
 
Join Date: Nov 2009
Posts: 10
Thanks: 1
Thanked 1 Time in 1 Post
Default moving elements from once place to another

I need to move the element "two" inside "six" without its descendant element "four". Also I'm not using identity transformation, only using mode to move the element.

Please tell me you suggestions.

input xml:
Code:
<one>aaa
<two>bbb<three>ccc</three><four>ddd</four></two>	
<five>eee</five>
<six>fff</six>	
</one>
current output:
Code:
<first>aaa
	<fourth>ddd</fourth>	
	  <fifth>eee</fifth>
	  <sixth>
      <second>bbb<third>ccc</third>
         <fourth>ddd</fourth>
      </second>fff</sixth>	
</first>
expected output xml:
Code:
<first>aaa		
<fourth>ddd</fourth>
<fifth>eee</fifth>
<sixth><second>bbb<third>ccc</third></second>fff</sixth>	
</first>
xslt:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output indent="yes"/>   
  
  <xsl:template match="one">
    <first>
      <xsl:apply-templates/>
    </first>
  </xsl:template>

  <xsl:template match="two">
    <xsl:apply-templates select="descendant::four"/>
  </xsl:template>

  <xsl:template match="two" mode="move">
    <second>
      <xsl:apply-templates/>
    </second>
  </xsl:template>

  <xsl:template match="three">
    <third>
      <xsl:apply-templates/>
    </third>
  </xsl:template>

  <xsl:template match="four">
    <fourth>
      <xsl:apply-templates/>
    </fourth>
  </xsl:template>

  <xsl:template match="four" mode="move"/>

  <xsl:template match="five">
    <fifth>
      <xsl:apply-templates/>
    </fifth>
  </xsl:template>

  <xsl:template match="six">
    <sixth>
      <xsl:apply-templates select="preceding::two" mode="move"/>
      <xsl:apply-templates/>
    </sixth>
  </xsl:template>

</xsl:stylesheet>

Regards
Priyan

Last edited by priyan24; October 15th, 2013 at 08:43 AM..
 
Old October 17th, 2013, 01:47 AM
Authorized User
 
Join Date: Nov 2009
Posts: 10
Thanks: 1
Thanked 1 Time in 1 Post
Default

some how i managed code given below for your reference

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output indent="yes"/>   
  
  <xsl:template match="one">
    <first>
      <xsl:apply-templates/>
    </first>
  </xsl:template>

  <xsl:template match="two">
    <xsl:apply-templates select="descendant::four" mode="move"/>
  </xsl:template>

  <xsl:template match="two" mode="move">
    <second>
      <xsl:apply-templates/>
    </second>
  </xsl:template>

  <xsl:template match="three">
    <third>
      <xsl:apply-templates/>
    </third>
  </xsl:template>

  <xsl:template match="four" mode="move">
    <fourth>
      <xsl:apply-templates/>
    </fourth>
  </xsl:template>

  <xsl:template match="four"/>

  <xsl:template match="five">
    <fifth>
      <xsl:apply-templates/>
    </fifth>
  </xsl:template>

  <xsl:template match="six">
    <sixth>
      <xsl:apply-templates select="preceding::two" mode="move"/>
      <xsl:apply-templates/>
    </sixth>
  </xsl:template>

</xsl:stylesheet>
Thank you





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check whether an elements contains another elements or not? metinhoclam XSLT 5 August 14th, 2010 10:11 AM
Chap 16 pg 574: Elements not supported Elements not known tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 August 6th, 2009 02:48 PM
footer doesn't appear in right place Rachel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 January 7th, 2009 02:44 PM
Logging in from another place Hadware General .NET 0 December 14th, 2004 03:39 PM
convert elements based on place in document jefke XSLT 2 May 17th, 2004 05:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.