xsl-list
[Top] [All Lists]

Re: [xsl] RE: Counting preceding elemets of similar node, but in different branch

2008-07-23 06:22:48
It seems, following would work

<xsl:template match="QUESTION">
  <xsl:value-of select="count(preceding::QUESTION) + 1"/> = <xsl:value-of
select="@ID"/><br/>
</xsl:template>

On 7/23/08, Karlmarx Rajangam 
<karlmarx(_dot_)rajangam(_at_)questionmark(_dot_)co(_dot_)uk> wrote:
I have requirement to display certain id's in a sequential numbering
order. My xml is something like [and pls ignore any spell / case
mistakes]

       <root>
               <something>
                       <assessQ>
                               <header/>
                               <Block>
                                       <blockID>xxxx</blockID>
                                       <questions>
                                               <QUESTION ID="1" />
                                               <QUESTION ID="2" />
                                               <QUESTION ID="3"/>
                                       </questions>
                               </Block>
                       </assessQ>
                       <assessQ>
                               <header/>
                               <Block>
                                       <blockID>yyy</blockID>
                                       <questions>
                                               <QUESTION ID="1" />
                                               <QUESTION ID="2" />
                                       </questions>
                               </Block>
                       </assessQ>
               </something>
       </root>

And in my xslt (Ver 1), I have something like <xsl:apply-templates
select="something/assessQ/Block/questions"/> [I think I cannot change
this due to various other elements]

And what I am do is something like
1= 1
2= 2
3= 3
4= 1
5= 2 and so on....

so, i tried to use position,

<xsl:template match="QUESTION">
       <xsl:value-of select="position()"/> = <xsl:value-of
select="@ID"/><br/>
</xsl:template>

but I released the mistake after seeing the result, 3=3 is being
followed by again by 1=1, ... instead of 4=1.

So, i think i must use preceding-sibling and/or some other logic to
calculate how many <QUESTION/> elements are there before it. Pls can you
suggest the best way to handle this? Hope there might be some solution?

Thanks,
karl


-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--