Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How do i select/compare multiple text nodes spread out in a document?

Reply
Thread Tools

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

 
 
Cali
Guest
Posts: n/a
 
      08-10-2005
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

 
Reply With Quote
 
 
 
 
Steve Jorgensen
Guest
Posts: n/a
 
      08-10-2005
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" <killycali007-> 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


 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      08-10-2005
Hi,

Tempore 08:01:15, die Wednesday 10 August 2005 AD, hinc in foro {comp.text.xml} scripsit Cali <killycali007->:

> 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:age[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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset Question - Odd results with single xml nodes vs multiple nodes th3dude ASP .Net 0 01-03-2007 03:24 PM
Why treat text nodes as nodes? Xamle Eng XML 8 05-28-2005 01:11 PM
Text nodes and element nodes query asd Java 3 05-23-2005 10:01 AM
selecting nodes between other nodes Timo Nentwig XML 1 06-17-2004 04:54 AM
Reality check: Is it sensible to link XML nodes to other XML nodes in the same file? gavnosis XML 0 08-02-2003 08:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57