[xsl] Finding the position of a node within a subset of nodes

Subject: [xsl] Finding the position of a node within a subset of nodes
From: John Sands <WonkoWatson@xxxxxxxxx>
Date: Thu, 27 Feb 2003 09:22:51 -0500
I have an XML document representing an evaluation form containing
three types of sections that can appear any number of times in any
order (the three types of sections are comment sections, instruction
sections, and question sections). Here's a fragment:

      <instruction_text>A whole bunch of bogus instructions are here</instruction_text>
    <questions name="Bogus Section">
      <question name="Bogus question" answer_scheme_id="1" />
      <comment_text>one line of bogus comments here</comment_text>
    <questions name="Another Bogus Section">
      <question name="Bogus question" answer_scheme_id="1" />

I'm processing them in the order they appear in the document with

 <xsl:apply-templates select="//sections/questions | //sections/instructions | //sections/comments"/>

The problem is that in the 'questions' template, I want to output the
position of that section without regard to other types of sections. In
other words, the first 'questions' section must be 'Section 1', even
if it is preceded by comments and instructions sections. Before I
added the comments and instructions, I was just doing this:

<xsl:template match="questions">
 <xsl:variable name="section" select="position()"/>

But in the above example, I'm outputting 'Section 2: Bogus Section'
where I want it to be Section 1. Is there a way to find the position
within the subset without changing the processing order?

John Sands

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread