473,378 Members | 1,492 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,378 software developers and data experts.

How to replace a tag in xml document with xslt

Hi, I am quite new to xsl, so maybe there is a pretty easy solution to
this, but I couldn't find a solution anywhere.
Basically I am trying to replace a pattern of tags with other tag. For
example if my xml looks like this:

<a>
<b>
<c>
<c>some text</c>
</c>
</b>
<a>

And I want to replace <c><c> with <d> so my output would be
<a>
<b>
<d>some text</d>
</b>
</a>

The problem is that I don't know an absolute path to c/c it could be
anything, I just want to match on <c><c> no matter how far down it is.
Can this be done with xslt.
Thank you in advance

Nov 23 '05 #1
1 1372
> The problem is that I don't know an absolute path to c/c it could be
anything, I just want to match on <c><c> no matter how far down it is.
Can this be done with xslt.


This isn't heavily tested, but it might get you started in the right
direction. Someone here in the group with more XSL experience can
probably provide a better solution:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- This matches <c> elements that are parents of another <c>
element, and replaces them with a <d> element containing the text
nodes of the child <c> element. -->
<xsl:template match="c[child::c]">
<d><xsl:value-of select="c/text()"/></d>
</xsl:template>

<!-- This matches everything else and just copies it to
the output. -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

-- Lars

--
Lars Kellogg-Stedman <82*************@jetable.net>
This email address will expire on 2005-11-23.

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Geathaa | last post by:
Hi everyone, I want to transform a xml document containing the description of a menu tree to HTML. The MenuTree XML contains the target URL for each tree node. Some URL's contain parameters...
5
by: Stephan Hoffmann | last post by:
Hi, I use XML mainly as a source for HTML. HTML browsers 'know' certain entity references like &eacute; or &auml;. When I use XSL to transform XML to HTML or XML, these entities are replaced...
9
by: Jiho Han | last post by:
Suppose I have an xml fragment like: <mother> <child name="Bob" sex="M"/> <child name="Jane" sex="F"/> ... </mother> If I wanted to replace the <mother> element to <father> element, what is...
4
by: Cathie | last post by:
Hi All, I am trying to get my style sheet to work. It works fine in IE but I can't get it to work in .net. Below is the function I use for transforming, where advancedOptionsFile is the path...
7
by: Yourself | last post by:
Hi, say I have the following XHTML document: <div id="Fred"> <div id="Bert"> <div id="Jim"> <p>Hello</p> <p>etc</p> </div> <div id="Bob"> <p>Goodbye</p>
5
by: DarthDaddy | last post by:
I hope to explain this properly. Here is a sample section of a file I am working with: <achievements> <achievement> <item name="COURSE_COMPLETION_DATE">19930630</item> <item...
3
by: Alois Treindl | last post by:
A simple XSL question from a newbie: In an xml document which I transform via xsl into html output, I have some text which I want to be suppressed. The tags looks like this <anchor_ref...
1
by: dewey | last post by:
Hi, This, I'm sure, is a very simple problem. I'm trying to use the xslt document() function to add a piece of information from a second xml file. The main xml has a list of football teams,...
1
by: Namshub | last post by:
I was wondering if there is a simple method of replacing characters within the xml document. I'm looking at writing a Biztalk Pipeline that escapes illegal characters before they are processed...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.