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

Is it possible to modify a source node using XSLT?

Hi,

I have ran into a situation that I think should be possible, but I am
fairly new to XSLT so maybe not.

Suppose I have the following document
<ROOT>
<FOO name="A">
<CHILD name="B"/>
</FOO>
</ROOT>

I am creating a new XML doc using XSLT, and I change the name attribute
of the first node FOO in my target doc. The name attribute of CHILD is
dependent on it's parent, i.e. it's built from the parent name. So I
select the parent name with XPATH "../@Name", but it returns the name
from the source document. I need the name from the target document,
because the old name is no good. How can I do this? Is it possible to
modify a source node in XSLT? I can modify a DOM document in a program
easily, so it seems like it would be possible to do in XSLT. If I can
do this, then the task will be easy. Are there any other ways to
achieve this?
Many thanks for the help!
regards,

B

Jul 20 '05 #1
4 1617
"ti**********@hotmail.com" <ti**********@hotmail.com> writes:
Hi,

I have ran into a situation that I think should be possible, but I am
fairly new to XSLT so maybe not.

Suppose I have the following document
<ROOT>
<FOO name="A">
<CHILD name="B"/>
</FOO>
</ROOT>

I am creating a new XML doc using XSLT, and I change the name attribute
of the first node FOO in my target doc. The name attribute of CHILD is
dependent on it's parent, i.e. it's built from the parent name. So I
select the parent name with XPATH "../@Name", but it returns the name
from the source document. I need the name from the target document,
because the old name is no good. How can I do this? Is it possible to
modify a source node in XSLT? I can modify a DOM document in a program
easily, so it seems like it would be possible to do in XSLT. If I can
do this, then the task will be easy. Are there any other ways to
achieve this?
Many thanks for the help!
regards,

B


XSLT input tree is read only, however as far as I understand your
description you don't want to modify the source just generate a new
element with some name. You haven't given any indication of what element
name you need to generate. Also it needs to be @name not @Name, XML is
case sensitive.

What result document do you need to generate given the above input??

David

Jul 20 '05 #2
Hi,

So the source is read only? That is good to know I suppose, although
it seems odd to me. Anyway, let me try to explain a little more. My
target document might look like this:

<TARGET>
<FI name="Changed">
<CHILD_FI name="Changed_1"/>
</FI>
</TARGET>

Notice that CHILD_FI name is based on FI. (with _1 appended) But I
cannot do this, because when I select the name from the parent, I get
the old name which is A. So instead my new name would end up being A_1,
which is not what I want.
Make sense?

many thanks,

B

David Carlisle wrote:
"ti**********@hotmail.com" <ti**********@hotmail.com> writes:

Hi,

I have ran into a situation that I think should be possible, but I am
fairly new to XSLT so maybe not.

Suppose I have the following document
<ROOT>
<FOO name="A">
<CHILD name="B"/>
</FOO>
</ROOT>

I am creating a new XML doc using XSLT, and I change the name attribute
of the first node FOO in my target doc. The name attribute of CHILD is
dependent on it's parent, i.e. it's built from the parent name. So I
select the parent name with XPATH "../@Name", but it returns the name
from the source document. I need the name from the target document,
because the old name is no good. How can I do this? Is it possible to
modify a source node in XSLT? I can modify a DOM document in a program
easily, so it seems like it would be possible to do in XSLT. If I can
do this, then the task will be easy. Are there any other ways to
achieve this?
Many thanks for the help!
regards,

B

XSLT input tree is read only, however as far as I understand your
description you don't want to modify the source just generate a new
element with some name. You haven't given any indication of what element
name you need to generate. Also it needs to be @name not @Name, XML is
case sensitive.

What result document do you need to generate given the above input??

David

Jul 20 '05 #3
Barry Andrews <ti**********@none.com> writes:
Hi,

So the source is read only? That is good to know I suppose, although
it seems odd to me. Anyway,
It would be very hard to define any behaviour to an xslt transformation
if the input could change during a transformation. There is no
requirement on a processor to process any templates in any particular
order, only that the results are combined into the final result tree as
specified, so if templates could alter the input, the behaviour of every
stylesheet would be undefined, as the input to each template would
depend on implementation-specific choices of the order of template
execution.

This is the usual behaviour of any declarative/functional language.
If you evaluate a function f(x,y) a result is returned but there are no
side effects, in particular the inputs to a unction are never changed.

let me try to explain a little more. My
target document might look like this:

<TARGET>
<FI name="Changed">
<CHILD_FI name="Changed_1"/>
</FI>
</TARGET>

Notice that CHILD_FI name is based on FI. (with _1 appended) But I
cannot do this, because when I select the name from the parent, I get
the old name which is A. So instead my new name would end up being A_1,
which is not what I want.
Make sense?

In a typical transformation the names of the result elements bear no
relation at all to the names of the input elements. Think of converting
docbook to html, or html to SVG or ... When generating the name of any
element in the result you have access via xpath to any part of the
source, so any information that caused you to generate the name FI on
the parent element is available still so there is nothing to stop you
generating an element name that contains the string _FI. However you
haven't given any indication of the transformation that you are trying
to so I can't offer any code.

David

Jul 20 '05 #4
Thanks for the response!

You have answered my question about modifying the source very well.

I will try to post my XSLT code tomorrow when I get to work. It will
probably help explain what I am trying to do.
thanks,

B

David Carlisle wrote:
Barry Andrews <ti**********@none.com> writes:

Hi,

So the source is read only? That is good to know I suppose, although
it seems odd to me. Anyway,

It would be very hard to define any behaviour to an xslt transformation
if the input could change during a transformation. There is no
requirement on a processor to process any templates in any particular
order, only that the results are combined into the final result tree as
specified, so if templates could alter the input, the behaviour of every
stylesheet would be undefined, as the input to each template would
depend on implementation-specific choices of the order of template
execution.

This is the usual behaviour of any declarative/functional language.
If you evaluate a function f(x,y) a result is returned but there are no
side effects, in particular the inputs to a unction are never changed.
let me try to explain a little more. My
target document might look like this:

<TARGET>
<FI name="Changed">
<CHILD_FI name="Changed_1"/>
</FI>
</TARGET>

Notice that CHILD_FI name is based on FI. (with _1 appended) But I
cannot do this, because when I select the name from the parent, I get
the old name which is A. So instead my new name would end up being A_1,
which is not what I want.
Make sense?


In a typical transformation the names of the result elements bear no
relation at all to the names of the input elements. Think of converting
docbook to html, or html to SVG or ... When generating the name of any
element in the result you have access via xpath to any part of the
source, so any information that caused you to generate the name FI on
the parent element is available still so there is nothing to stop you
generating an element name that contains the string _FI. However you
haven't given any indication of the transformation that you are trying
to so I can't offer any code.

David

Jul 20 '05 #5

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

Similar topics

2
by: Ralf Wahner | last post by:
Dear Masters of XSLT Could I ask you for a clue on the following question? I'd like to use XSLT to transform an XML source file to LaTeX. In the following small example the <para> Element...
2
by: Lance Riedel | last post by:
I was wondering if anyone has seen/knows of a solution to the following: given a document that has been translated through xsl, if you have a character offset in the translated document, can you...
1
by: Eric | last post by:
I am trying to figure out a good way to implement a XSLT transformation. Basically my goal is that I want to be able to ouput the following XML in a document: <chart type="pie" width="100"...
1
by: Alex | last post by:
Hello, I don't have sufficient experience with XSLT, and would really appreciate somebody's help in me giving ideas on solving a problem I have. Let's consider the following XML file: ...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
1
by: tslettebo | last post by:
Hi all. I've read Michael Kay's "XSLT" book, and used XSLT successfully as an HTML template system at our company (using basically the "fill-in-the-blanks" pattern of XSLT use: A template...
5
by: patrin | last post by:
Hi All, given the source document: <?xml version="1.0" encoding="UTF-8"?> <root> <child> <test id="1" name="first child"/> </child> <child>
4
by: Lord0 | last post by:
Hi there, Is the following possible with XSLT? Given the following example XML docs: <!-- doc 1--> <user> <username>myUsername</username> <password></password> <phone>12345</phone>
5
by: Simon Brooke | last post by:
This is supposed to be a very simple XSL stylesheet to strip styling information out of HTML documents - it could not be more basic. And yet, it doesn't work. I'm obviously getting something very...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
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
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...
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...

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.