[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:

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

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

 <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?

Thanks,
John Sands



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


Current Thread