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

How do i select/compare multiple text nodes spread out in a document?

Please bear with me, I have been reading about XSL for a couple hours.

I have an XML document that contains multiple <page> tags interspersed
throughout the tree.

<text>
....
<page>1</page>
....
<page>2</page>
</text>

These are not always going to be in the same level. To get the sequence
of all the pages I correctly figured I could use:

<xsl:template match="/">
<xsl:for-each select='.//page'>
Page <xsl:value-of select="text()"/><br/>
</xsl:for-each>
</xsl:template>

I also want to evaluate whether the text value of the current <page>
node is in sequence with the previous one, if not then mark the output.
I would have imagined that it would be something like this but it
doesnt work:

<xsl:template match="/">
<xsl:for-each select='.//page'>
<xsl:variable name="this_page_number" select="text()"/>
<xsl:variable name="thispos" select="position()"/>
<xsl:variable name="prev_page_number" select=".//page[$thispos
- 1]/text()"/>
<xsl:variable name="expected_prev_page_number"
select="$this_page_number - 1"/>
<xsl:if test="$expected_prev_page_number != $prev_page_number">
<strong>Sequence broken!</strong>
</xsl:if>
Page <xsl:value-of select="$this_page_number"/><br/>
</xsl:for-each>
</xsl:template>

I obviously have not yet grasped XSL. What is the correct solution?

Thank you,

Cali

Aug 10 '05 #1
2 1635
I think what might work is to get the sequence of page nodes, then do a
recursive template call where each call examines the first 2 nodes, and passes
a copy of the node set, minus the first node to itself using the remove()
function to remove the node.

On 9 Aug 2005 23:01:15 -0700, "Cali" <ki********************@yahoo.com> wrote:
Please bear with me, I have been reading about XSL for a couple hours.

I have an XML document that contains multiple <page> tags interspersed
throughout the tree.

<text>
...
<page>1</page>
...
<page>2</page>
</text>

These are not always going to be in the same level. To get the sequence
of all the pages I correctly figured I could use:

<xsl:template match="/">
<xsl:for-each select='.//page'>
Page <xsl:value-of select="text()"/><br/>
</xsl:for-each>
</xsl:template>

I also want to evaluate whether the text value of the current <page>
node is in sequence with the previous one, if not then mark the output.
I would have imagined that it would be something like this but it
doesnt work:

<xsl:template match="/">
<xsl:for-each select='.//page'>
<xsl:variable name="this_page_number" select="text()"/>
<xsl:variable name="thispos" select="position()"/>
<xsl:variable name="prev_page_number" select=".//page[$thispos
- 1]/text()"/>
<xsl:variable name="expected_prev_page_number"
select="$this_page_number - 1"/>
<xsl:if test="$expected_prev_page_number != $prev_page_number">
<strong>Sequence broken!</strong>
</xsl:if>
Page <xsl:value-of select="$this_page_number"/><br/>
</xsl:for-each>
</xsl:template>

I obviously have not yet grasped XSL. What is the correct solution?

Thank you,

Cali


Aug 10 '05 #2
Hi,

Tempore 08:01:15, die Wednesday 10 August 2005 AD, hinc in foro {comp.text.xml} scripsit Cali <ki********************@yahoo.com>:
Please bear with me, I have been reading about XSL for a couple hours.

I have an XML document that contains multiple <page> tags interspersed
throughout the tree.

<text>
...
<page>1</page>
...
<page>2</page>
</text>

I also want to evaluate whether the text value of the current <page>
node is in sequence with the previous one, if not then mark the output.
I would have imagined that it would be something like this but it
doesnt work.


Instead of going to mess with 'position()', try the more reliable 'preceding' axis:

<xsl:template match="/">
<xsl:for-each select='.//page'>
<xsl:variable name="this_page_number" select="."/>
<xsl:variable name="prev_page_number" select="preceding::page[1]"/>
<xsl:variable name="expected_prev_page_number" select="$this_page_number - 1"/>
<xsl:if test="$expected_prev_page_number != $prev_page_number">
<strong>Sequence broken!</strong>
</xsl:if>
Page <xsl:value-of select="$this_page_number"/><br/>
</xsl:for-each>
</xsl:template>
regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Vincit omnia simplicitas
Keep it simple
Aug 10 '05 #3

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

Similar topics

5
by: Colman | last post by:
Howdy all! I guess I'm a newbie, because I am stumped (or maybe just too durned tired). Here's what I got... CREATE TABLE `nodecat_map` ( `nodecat_id` mediumint(8) unsigned NOT NULL...
1
by: Neil | last post by:
Folks, I've got a problem at work, and I'm hoping that someone out there may have had something similar (although I doubt it!) or may be able to offer some advice. I'm in the process of...
6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
4
by: Michael Schuerig | last post by:
I'm trying to change the options of a select element by setting its innerHTML. Here's a demo case: <html> <head> <script language="javascript" type="text/javascript"> function addOpts() { var...
6
by: Adam Tilghman | last post by:
Hi all, I have found that IE doesn't seem to respect the <SELECT> "multiple" attribute when set using DOM methods, although the attribute/property seems to exist and is updated properly. Those...
13
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
4
by: praveen | last post by:
I have a form with treeview control loaded from xml document,text box, two buttons named "Find" and "FindNext" and my treeview which looks like below. Details |__ policy status |__ created by...
1
by: gplott | last post by:
I have an XML document that has multiple childe nodes like the one at the end of this message What syntax would I use with selectNodes to select all viewentry nodes that have an entrydata...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: 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...

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.