473,789 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1524


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
1606
by: jamesfin | last post by:
Dear XMLers, Please guide me... I have a simple xml file... <URLTest>
11
5159
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 is the input element. The left column is right aligned and the right column is left aligned. I would like to replace this table with code that does not use a table for layout, and was hoping someone might be able to help me with the HTML and...
2
2063
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 HTML from user input (for a bespoke CMS) so that users can put in their own headings, lists and links etc. This is great and gets round all the issues of apostrophes etc. when inserting informaiton into a database for me.
8
4353
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 assuming that I'd need to do this in the onload event - but I don't know much about Javascript. Please Help! Thanks
3
2679
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 application, and for now, I would like to replace the operations on my data type vect3 (which is a float array) by operations on a vector float. The vect3 is simply a typedef to an array of floats so far.
7
2625
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 top right table cell. These elements should stay on one line and the table should keep a minimum width in order to prevent wrapping. -------------------------------------------------
2
2372
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. **************************************** <Root_Element> <Topic index="1"> <Sub_Topic> <Notes></Notes>
13
2321
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 the output from a custom Excel spreadsheet, and creates a Final Cut Pro sequence in XML. Due to the way Excel handles nested repeating elements, I need to find a way to replace a dummy element I have created with a whole series of repeating elements....
16
1990
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. Most of the internal anchors follow a very standard layout, and are associated with an h3 heading. I was wondering whether there was any reason not to change these <a name=" anchors to <h3 id=" anchors? I gather that all recent browsers work...
29
19291
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 site and so far doing this has saved about 8KB of javascript (lots of ajax/dynamic elements). I just
0
9663
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
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9979
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
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6765
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
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4090
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
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.