473,327 Members | 2,065 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,327 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 1634
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. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.