473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

To delete a unwanted sub element using xsl

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 7265
Dormilich
8,658 Expert Mod 8TB
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
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"><ital>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 Expert Mod 8TB
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 Expert Mod 8TB
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 Expert 2GB
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
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
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...
2
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
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 ...
10
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...
7
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...
7
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
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
by: Zuhaib Hyder | last post by:
how to delete client file using c# or javascript ? file delete prmissions are already given?
5
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.