Re: [xsl] count elements in variable

Subject: Re: [xsl] count elements in variable
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 15 Oct 2013 09:52:40 +0100
On 15/10/2013 09:09, Torsten Schassan wrote:
Hi there,


I define a variable and traverse through a folder to collect files which I want to process. (XSLT2)

<xsl:variable name="descriptions"
select="collection(iri-to-uri('file:///d:/mss?select=tei-msDesc.xml;recurse=yes'))"/>



Next I process single elements:

<xsl:apply-templates select="$descriptions/descendant::tei:msDesc">
   <xsl:sort select="descendant::tei:msIdentifier/tei:idno/@sortKey"/>
</xsl:apply-templates>



Within the template I want to add a running number to each element:

<xsl:template match="tei:msDesc">
  <xsl:variable name="docKey">
    <xsl:value-of select="count(preceding::tei:msDesc)"/>
  </xsl:variable>
...
</xsl:template>


But this last step simply doesn't work. Does anybody have a clue what I'm missing here?

Best, Torsten



"doesnt work" isn't very descriptive but count() counts the preceding elements in the source, not taking account of the sorting. You probably just want position()



Also do


<xsl:variable name="docKey"select="count(preceding::tei:msDesc)"/>

not

<xsl:variable name="docKey">
    <xsl:value-of select="count(preceding::tei:msDesc)"/>

except that you want


<xsl:variable name="docKey"select="position()-1"/>


David

--
google plus: https:/profiles.google.com/d.p.carlisle

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________


Current Thread