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

Replacing elements

Hi mates! :)

The challange is like this: how to replace only one element in the
whole tree to something else?

Example:

Input:
<?xml version="1.0"?>
<html>
<head></head>
<body>
<b> some<u>thing</ul> </b>
</body>
</html>

into:
<?xml version="1.0"?>
<html>
<head></head>
<body>
<strong> some<u>thing</ul> </strong>
</body>
</html>

(<b> -> <strong>) ?

Mirek

Jun 21 '06 #1
4 1501


mi************@mensa.org.pl wrote:

The challange is like this: how to replace only one element in the
whole tree to something else? (<b> -> <strong>) ?


<xsl:template match="b">
<strong>
<xsl:apply-templates select="@* | node()" />
</strong>
</xsl:template>
then you need the identity transformation for the rest
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 21 '06 #2
Problem solved. The trick is to simply use:

<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>

Jun 21 '06 #3
mi************@mensa.org.pl wrote:
Problem solved. The trick is to simply use:

<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>


That isn't namespace-sensitive. You want to set the namespace URI as
well. At which point, you've essentially reinvented xsl:copy.

You also probably need to copy attributes.

Martin's answer is a cleaner one.
Jun 21 '06 #4
Thank you, you're 100% right.

Jun 22 '06 #5

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

Similar topics

8
by: jamesfin | last post by:
Dear XMLers, Please guide me... I have a simple xml file... <URLTest>
11
by: Peter Foti | last post by:
Hi all, I have a form that contains a 2 column table. In the left column is the description for a particular input (ie - "First Name", "Last Name", "Phone Number", etc.). In the right column...
2
by: thehuby | last post by:
Isn't inserting good data and getting it out of a db a pain in the a$$? I am going to be using the Markdown text to HTML parser (http://daringfireball.net/projects/markdown/dingus) for creating...
8
by: gowens | last post by:
I have a page that contains several HREFs. Each HREF that I'm interested in has a common parameter (parmX). Does anyone have a script example on how to find-and-replace parmX with parmY? I'm...
3
by: Lars Grobe | last post by:
Hi, first hello, I am new to the list, and I guess my question will show that clearly. I want to use some vector operations (at the moment altivec) in existing code. It is a raytracing-based...
7
by: Daniel Kabs | last post by:
Hi there, for a long time I've been using tables to layout elements on a web page. Example: Say we have a 2x2 table and I'd like to put text (left aligned) and buttons (right aligned) in the...
2
by: James Fifth | last post by:
Hello and God Bless, I am stumped trying to get a simple xml database replacing certain data with other data programmatically. This is what my xml looks like. ...
13
by: jtric | last post by:
Very new to XML/XSL, so please forgive me if this is an incredibly simple question. I've been pulling my hair out over this for several days now. I'm working on an internal application that takes...
16
by: Eric Lindsay | last post by:
I have a bunch of old web pages now in HTML 4.01 Strict I update every now and then with revised material. They were written back when using <a name=" was the normal method of including an anchor....
29
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
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
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...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.