473,378 Members | 1,334 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.

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 2072
da*********@gmail.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>your 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
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...
27
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
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:\>...
1
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
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...
9
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. ...
3
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...
1
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,...
6
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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...

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.