473,714 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

To delete a unwanted sub element using xsl

5 New Member
I have xml like

<root>
<parent>
<child1>Text</child1>
</parent>
</root>

I want to delete the unwanted sub element <child1> and output would be like <parent>Text</parent>.

Thanks in advance.
Nov 6 '08 #1
6 7281
Dormilich
8,658 Recognized Expert Moderator Expert
if the xml is that simple you can simply rewrite it.
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="parent"> // or any convenient xpath/name depending on the situation
  2.   <parent>
  3.     <xsl:value-of select="child1/text()"/>
  4.   </parent>
  5. </xsl:template>
regards
Nov 6 '08 #2
radhakrishnanrs
5 New Member
if the xml is that simple you can simply rewrite it.
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="parent"> // or any convenient xpath/name depending on the situation
  2.   <parent>
  3.     <xsl:value-of select="child1/text()"/>
  4.   </parent>
  5. </xsl:template>
regards

Thanks for info but it is not a simple xml file. It is a big xml file with lot of elements. I have tried the above sample, but it is not resulting the desired output. The xml file is actually looks like:

<site.info number="009" snumber="0122" wnumber="AtoZ" type="text"><it al>Rose,</ital> running text</site.info>

here it want to remove the element <ital>, I am using this xsl file as pre cleanup process.

Thanks in advance
Nov 6 '08 #3
Dormilich
8,658 Recognized Expert Moderator Expert
Thanks for info but it is not a simple xml file. It is a big xml file with lot of elements. I have tried the above sample, but it is not resulting the desired output.
the problem lies in the <template>'s match attribute. if you want to filter it from a more complex xml you'll probably need to copy the xml but those elements and insert the corrected elements.
some general code for xsl copy you'll find here in some of the threads (I'll look up some of them later). the principle is something like
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="node() | @*">
  2.   <xsl:copy select="."/>
  3. </xsl:template>
of cause this is without filter.
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="node()[not(ital)]">
  2. // ...
  3. // add attribute copy
this will exclude any elements with a <ital> child element from copying, now insert the just excluded elements
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="node()[ital]">
  2. // code similar to the already posted
note: this is a rough sketch of what I would do, still need to look up the exact code.

regards
Nov 6 '08 #4
Dormilich
8,658 Recognized Expert Moderator Expert
some general code for xsl copy you'll find here in some of the threads (I'll look up some of them later).
https://bytes.com/showthread.php?t=842976
https://bytes.com/showthread.php?t=841347
**********
Nov 6 '08 #5
jkmyoung
2,057 Recognized Expert Top Contributor
Assuming you're just filtering out the ital nodes:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="ital">
  2.   <xsl:apply-templates/> <!-- apply-templates but do not copy the node -->
  3. </xsl:template>
  4.  
  5. <xsl:template match="*"> <!-- copy template -->
  6.   <xsl:copy>
  7.     <xsl:copy-of select="@*"/>
  8.     <xsl:apply-templates/>
  9.   </xsl:copy>
  10. </xsl:template>
  11.  
Nov 6 '08 #6
radhakrishnanrs
5 New Member
Thanks all, it Worked correctly:)
Nov 17 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1615
by: frankabel | last post by:
Hi all! I have the following xml file: " <items> <item>hi</item> <item>hello</item> </items> " and need to read all the content between <items> and </items> tags and saved in a string, in this case:
2
1553
by: AR | last post by:
Hi, How can I get strings separately which contain text nodes of a given element using XSL and XPath? For example, <a> aaa 111 <b>
3
21536
by: Brian Underhill via DotNetMonster.com | last post by:
I am trying to delete an element from an array. I have an array of 52 elements and I want to search for an element and delete it. Therefore, making it an array of 51 elements. is it just delete MyArray; any help would be great....thanks
10
3396
by: Mark A. Odell | last post by:
Is there a way to obtain the size of a struct element based only upon its offset within the struct? I seem unable to figure out a way to do this (short of comparing every element's offset with <offset>). What I would like to do is create an API something like this: #include <stddef.h> struct MemMap { unsigned char apple; // 8 bits on my platform
7
1355
by: python | last post by:
after del list , when I use it again, prompt 'not defined'.how could i delete its element,but not itself? except list.remove(val) ,are there other ways to delete list 's elements? and , I wrote: list1= def method1(): global list1
7
4346
by: JH Programmer | last post by:
Hi, is there any ways that allow us to delete an element in between? say int_val: 1 int_val: 2 int_val: 3
7
5907
by: =?utf-8?B?5YiY5piK?= | last post by:
Hi, folks, Is it possible to delete an element from a sorted array with O(1) time? Best regards
1
3832
by: Zuhaib Hyder | last post by:
how to delete client file using c# or javascript ? file delete prmissions are already given?
5
3877
by: Edwin | last post by:
I am trying to write an application among which one of the functions is to determine the number of unique extensions found in a directory and all of its sub directories. I am trying to use Linq to XML to do this. Below is the code being used to accomplish what I am trying to do. In the "if" statement, I am trying to update the <Count></CountElement to "TESTING". However what I will really want is to add 1 to the existing numerical...
0
3707
by: Big Daddy | last post by:
I am trying to do all my DB access through LINQ. For example, I am trying to delete a record from the JobQueue table. There’s a couple ways I could do this: 1. Method 1 – The disadvantage is that it makes 2 calls to the DB: one to get the record and then one to delete it: using (LogicDataContext ctx = new LogicDataContext(m_strConnect)) { JobQueue jq = ctx.JobQueues.Single(queue =queue.JobQueueNo ==
0
8814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9187
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9079
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5961
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4730
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3160
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.