XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 15th, 2012, 06:40 PM
ice.kreng ice.kreng is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 6 ice.kreng User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 25 sec
Reputation Power: 0
Output specific nodes and child elements and delete other parent and child nodes

Hi Experts!

Can you help suggest how I can insert Returned tag(under secondary) on the Inventory tag(under Primary)
and then output only the Profile and all its aattributes under Primary as below.

Input:

<MergedProfile>
<Primary>
<Profile>
<Primary>
<Books></Books>
<Magazines></Magazines>
</Primary>
<Inventory action="mod">
<Borrowed action="mod">
<January>24</January>
</Borrowed>
</Inventory>
</Profile>
</Primary>

<Secondary>
<Profile>
<Inventory action="mod">
<Returned>
<January>7</January>
</Returned>
</Inventory>
</Profile>
</Secondary>
</MergedProfile>


Output Desired:
<Profile>
<Primary>
<Books></Books>
<Magazines></Magazines>
</Primary>
<Inventory action="mod">
<Borrowed action="mod">
<January>24</January>
</Borrowed>
<Returned action="del">
<January>7</January>
</Returned>
</Inventory>
</Profile>

I have the below code playing into - it inserts but copying all.
Have changed the template match and apply-templates to /MergedProfile/Primary but it either returns nothing or everything

<xsl:stylesheet version="1.0">
<xslutput method="xml" version="1.0"/>

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="/MergedProfile/Primary/Profile/Inventory">
<xsl:element name="Returned">
<xsl:attribute name='action'>del</xsl:attribute>
<xsl:for-each select="../../../Secondary/Profile/Inventory/Returned/January">
<xsl:element name="January">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

Thanks! Appreciate your help. Can't find any sites related to this...

Reply With Quote
  #2  
Old March 21st, 2012, 07:49 PM
ice.kreng ice.kreng is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 6 ice.kreng User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 25 sec
Reputation Power: 0
I'm closing the thread cause I got the desired output already
Just to share what I did,

Adding to my existing code that I was playing with,
I removed the Secondary node and all its contents
<xsl:template match="Secondary"></xsl:template>


and remove tag MergedProfile and Primary, but retaining its contents
<xsl:template match="Primary">
<xsl:apply-templates select="node()"/>
</xsl:template>

<xsl:template match="MergedProfile">
<xsl:apply-templates select="node()"/>
</xsl:template>

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Output specific nodes and child elements and delete other parent and child nodes

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap