C
Cali
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
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