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

Looking A Nodes From Within Nodes


I've written a template that does some work on a subtree, but I want to
replace the subtree that I originally worked on. How would I do this?

Confused, Okay, here's an example:

<node>
<node>
<node>
</node>
<node>
</node>
</node>
<node> **
<node>
</node>
<node>
</node>
</node> **
</node>

This is a binary tree full of "node" tags. Let's let I was working on
the subtree starting at the node tag I've indicated by the **s. Let's
say I've done my work on the subtree and I want to replace the subtree
in this master tree with the one I've just changed. I also want to
change the top level node tag (for example, updating the attribute tag).
I can't do something like

<xsl:element>
<xsl:attribute counter="/node/@counter+1"/>
<xsl:copy-of select="/node/*[position()=1]"/>
<xsl:copy-of select="$outputofsubtreework"/>
</xsl:element>

Because, while it will work in this case, I don't know in advance how
many levels the tree will have.

Can anyone help me out here? :)

Johnny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
10 1557

Ack! Sorry, I phrased the problem incorrectly. When I said "top level
node tag", I meant to indicate the parent of the root of the subtree.
So, in this example, it's the root of the tree, but in another scenario,
it might not be.

And apologies for the example, by indentations didn't show up correctly.
__<


Johnny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
> I want to replace the subtree
in this master tree with the one I've just changed. I also want to
change the top level node tag (for example, updating the attribute tag).
I can't do something like

<xsl:element>
<xsl:attribute counter="/node/@counter+1"/>
<xsl:copy-of select="/node/*[position()=1]"/>
<xsl:copy-of select="$outputofsubtreework"/>
</xsl:element>

Because, while it will work in this case, I don't know in advance how
many levels the tree will have.


Hi,

Maybe you can use something like this:

<xsl:element name="node">
<xsl:attribute name="counter"><xsl:value-of select="@counter +1 "/></xsl:attribute>
<xsl:copy-of select="preceding-sibling::*"/>
<xsl:copy-of select="$outputofsubtreework"/>
<xsl:copy-of select="following-sibling::*"/>
</xsl:element>

or, if this doesn't work , give some more details

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #3

Hi, Joris, thanks for the help, I will try your code out and see if it
works.

Johnny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
Joris, on a side note, can you tell me why doing this:

<xsl:variable>
<xsl:element name="node">
<xsl:attribute name="att1"><xsl:value-of select="'data'"/>
<xsl:attribute name="att2"><xsl:value-of select="'data'"/>
<xsl:element name="node">
<xsl:attribute name="att1"><xsl:value-of select="'data'"/>
<xsl:attribute name="att2"><xsl:value-of select="'data'"/>
</xsl:element>
<xsl:element name="node">
<xsl:attribute name="att1"><xsl:value-of select="'data'"/>
<xsl:attribute name="att2"><xsl:value-of select="'data'"/>
</xsl:element>
</xsl:element>
</xsl:variable>

Gives me a fragment. I was trying to create this tree:

<node att1='data' att2='data'>
<node att1='data' att2='data'/>
<node att1='data' att2='data'/>
</node>

But because it's a fragment, I cannot do anything like
$var/*[position()=1] or $var/* and I need to do that. How should I
restructure my code to give me a nodeset?

Regards

Johnny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
Hi,
Joris, on a side note, can you tell me why doing this:
<xsl:variable>
<xsl:element name="node">
<xsl:attribute name="att1">data</xsl:attribute>
<xsl:attribute name="att2">data</xsl:attribute>
<xsl:element name="node">
<xsl:attribute name="att1">data</xsl:attribute>
<xsl:attribute name="att2">data</xsl:attribute>
</xsl:element>
<xsl:element name="node">
<xsl:attribute name="att1">data</xsl:attribute>
<xsl:attribute name="att2">data</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:variable>
Gives me a fragment. I was trying to create a tree.
Well, actually it creates a result tree.
It's only impossible (in XSLT 1.0) to consult a fragment of the result tree or apply an Xpath expression on it.
How should I restructure my code to give me a nodeset?

I'm afraid you can't. In XSLT, you can't create nodesets.
You can, however, convert a result tree to a nodeset with an extension function such as 'exsl:node-set()'

regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #6

Forget that last message, I've sorted it out, but the original problem
is still bothering me.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #7
> Forget that last message, I've sorted it out, but the original problem
is still bothering me.


What's still bothering you? Give some more details and I'll try to help.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #8
>>
How should I restructure my code to give me a nodeset?

I'm afraid you can't. In XSLT, you can't create nodesets.
You can, however, convert a result tree to a nodeset with an extension
function such as 'exsl:node-set()'
<<

However, the problem with that is that extension functions are processor
specific, and not all processors will support them. Am I correct? I am
trying to avoid placing restrictions on my code because of problems like
this, but if I have to, I don't have a choice. Out of curiosity, which
processor does that exsl: prefix come from?
Regards

Johnny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #9
Hi,
The problem with that is that extension functions are processor
specific, and not all processors will support them. Am I correct? You're absolutely right. That's why I'd never use it myself. My philosophy is: when a general feature is missing in a W3C recommendation, just wait until the next version is developed; don't use 'extension' functions of any sort or weird hacks: wait until there's a short, standardized way to do it. Off course, this philosophy is very hard to maintain in a professional environment. But, since I'm only a student, I can perfectly afford to think such.
trying to avoid placing restrictions on my code because of problems like
this, but if I have to, I don't have a choice. There's another option: use 2 stylesheet that are being applied one after each-other.
Or you could redesign the the algorithm of your XSLT.
Out of curiosity, which processor does that exsl: prefix come from?

I'm not sure. Check http://www.exslt.org/ for that.

regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceteru3m censeo XML omnibus esse utendum
Jul 20 '05 #10
Joris, you're being a real help here, I really appreciate your
assistance. I'm still fairly new to XSL, so I've having lots of
problems.

The original problem was this: I have a binary tree and I'm working on a
subtree of this master tree. I want to replace an attribute value on the
root of the tree, but I can't say in advance how many levels there will
be between the root of the subtree and the root of the master tree. In
fact, the subtree result will not be in the same order as the original
subtree I started working with (e.g. the attributes will be different).

What I would like to know is how can I replace the subtree on the master
tree and update the root node's attribute, given that I can't say in
advance how many levels there will be between the subtree and the root.
So in one scenario, soing $current/../../.. (root + 3 levels) will get
you to the root, but in another, $current/.. (root + 1 level) will do
the same.

I know you can't change the contents of variables, so if the master tree
was in a variable called "tree", I'd have to put the result of the
subtree replace in a variable called "tree2" or something else along
those lines.

I hope this helps you understand the problem I'm having.

Johnny

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #11

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

Similar topics

9
by: Rolf Kemper | last post by:
Dear Experts, I got stuck with the following problem and need your help. What I wnat to do is to get a set of distinct nodes. Before the distinct I have selected the multiple occourences...
8
by: Xamle Eng | last post by:
One of the things I find most unnatural about most XML APIs is that they try to abstract both elements and text into some kind of "node" object when they have virtually nothing in common. The...
1
by: Jonathan Wilson | last post by:
I am looking for a C++ class library that can store data in a tree. The class library needs to be: 1.Available under a licence like GPL, LGPL or BSD so I can use it in my GPL program and 2.Usable...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
6
by: Paul J Lay | last post by:
I am using the XmlDocument Select Nodes method and it seems to work OK except that it returns embedded nodes in the collection when I only want the nodes that are not embedded. For example I have...
5
by: JJ | last post by:
Hi all, Im looking for a better way to handle the exeption if you try to find a node that doesnt exists? It usualy breaks in a object exeption. Now i have to use the try en catch option.. ...
1
by: Cremoni | last post by:
I'm looking for a visual scripting language to write poker logic. There must be several things out there, but I haven't been able to find anything suitable. I've seen similar systems in the past. I...
0
by: stardust | last post by:
Hi everyone, Within a Winform application, a treeview is contained in a User Control and the User Control is then located within a splitview. When the UserControl added some nodes into the...
8
by: Vikram Vamshi | last post by:
If I execute XmlNode.SelectNodes("some xpath query") and then use foreach to iterate over it. Will it guaratee that the order of nodes I get will be same as the order of nodes in the original xml...
6
by: sandy | last post by:
I am creating a class (or so I hope) which is to be a JobCollection, linked list of 'Job'. Job is another class already created. JobCollection is just the linked list manager. I have to have...
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: 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
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?
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
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
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...

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.