473,946 Members | 19,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Altering a leaf node

Hello,

Given a XML document, an XPath to a leaf node, and a string value, what
is the briefest XSLT transform to change that node's value to the
given string? The node is unique, unrepeated, and guaranteed to exist.

The real life scenario is an application's configuration file. I want
to extract a particular config parameter, do some non-trivial
transformations on it (external to XSLT) , then put the transformed
value back. How can I accomplish this?

-Dan

Nov 14 '06 #1
4 2102
da*********@gma il.com wrote:
Given a XML document, an XPath to a leaf node, and a string value, what
is the briefest XSLT transform to change that node's value to the
given string? The node is unique, unrepeated, and guaranteed to exist.
You can't "put back" a value using XSLT. What you do is generate a new
document that reflects the changes you want to make.

In this case: start with the identity transformation, then add one more
template which matches on that XPath and recreates the node with the
altered value. Almost any decent XSLT tutorial will describe this
approach, since it's a fairly standard stylesheet design.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Nov 14 '06 #2
I read the W3C tutorial, and two others that came up early in Google.
But I'm still stumped. Can you point me at a good tutorial (or other
document) you like, that covers this?

Nov 15 '06 #3
Start with the identity template:

<xsl:template match="@*|node( )">
<xsl:copy>
<xsl:apply-templates select="@*|node ()"/>
</xsl:copy>
</xsl:template>

Then add a template to describe the exceptional behavior. If you're
feeling paranoid, you may want to push its priority up a step or two,
but that probably isn't necessary in this simple case. (XSLT's implied
priority rules are very weak, but generally they're strong enough that
anything specific takes precedence over node() and @*.)

<xsl:template match="/xpath/to/your/interesting/leaf_node">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:text>you r new string value</xsl:text>
</xsl:copy>
</xsl:template>

Note that this assumes that if your leaf is an element, you really do
want to discard all its content and replace that with the new string --
even if it contains additional structure. If that isn't what you
intended, you'll have to think more precisely about what you _do_ want
to happen and write the appropriate transformation.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 15 '06 #4
This was exactly what I needed, thank you very much!

-Dan

Nov 15 '06 #5

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

Similar topics

4
6165
by: abhrajit | last post by:
I'm looking for a C/C++/Java library to create a balanced binary tree data structure given a set of leaf nodes as input. A leaf node should never become an interior node. So if I wish to create a tree that will have a,b,c & d as leaf nodes - this tree will contain nodes other than a,b,c & d as interior nodes: e.g. x / \
27
2302
by: C Gillespie | last post by:
Dear All, Hopefully I have a simple problem. Basically, I just want to alter some text with JS. Here is some of my test code: <snip> <script type="text/javascript"> var tmp='a';
0
2165
by: Marv | last post by:
Is it possible to print the path of all leaf nodes of an XML using XML::Simple This is the kind of output text that i'm trying to print (not the leaf node values but the path to reach them) c:\> perl ListLeafs.pl config.xml {RootNode}->{ChildNode1}->{LeafNode1} {RootNode}->{ChildNode1}->{LeafNode2} {RootNode}->{ChildNode1}->{LeafNode3} {RootNode}->{ChildNode2}->{LeafNode1} {RootNode}->{ChildNode2}->{LeafNode2}
1
4014
by: mazdotnet | last post by:
Hi, I'm using the asp:TreeView component of asp.net 2.0 and my tree is structure is Root -- Parent 1 --------- Leaf 1 --------- Leaf 2
3
4472
by: Uriah Piddle | last post by:
Hi Gang, I have a SiteMapPath, bound to a Site Map, that traces a hierarchy down to an 'Article' leaf node. But the Article page shows one of many individual articles depending on which article the user chooses in the Articles page. The way it is set up now, if the user selects a particular article in the 'Articles' page, the SiteMap looks like this: '. . . Articles Article'. Assuming the user choses a cookie baking article, I would like...
9
8414
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. However, after I alter the table and open microsoft excel to look at any changes; I get the following error: "This file is not in a recognizable format" If I do open the file in excel it looks like its not formatted.
3
2623
by: dkacher | last post by:
Hi - I'm looking for a way to generate a list of the fully-qualified paths to all of the leaf nodes in an XML Schema. The reason: I have a large schema for which I'm building a transform stylesheet; I need to be sure I've covered everything. With a list of the paths to all the leaves, I can check off my progress. Have you encountered a program that can generate such a list? Or any pointers about how to approach it? It seems that there...
1
5169
by: zufie | last post by:
Hi, I want to specifying a foreign key by altering a table. First, I create an ORDERS table without specifying a foreign key. Here is my code: CREATE TABLE ORDERS (Order_ID integer, Order_Date date, Customer_SID integer,
6
5305
by: Girish Kanakagiri | last post by:
If I want a class to be made as leaf class so that it cannot be inherited any more. How can I do this. I had heard that there is a keyword final, in Java which makes it as leaf class, but dont know what is its equivalent in C++. for example, make class C as leaf class. class A {
0
10162
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
11153
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
11340
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
10688
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
9886
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...
1
8253
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6112
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...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3541
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.