Re: [xsl] numbering nodes in result tree XSLT 2

Subject: Re: [xsl] numbering nodes in result tree XSLT 2
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 8 Aug 2007 22:46:34 +0100
Not at all sure I understood what your grouping criteria were, but
something like this seems to do something

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
  <xsl:strip-space elements="*"/>
  
  <xsl:template match="document">
    <a>
      <xsl:apply-templates select="note-block"/>
    </a>
  </xsl:template>
  
  <xsl:template match="note-block">
    <xsl:text>&#10;</xsl:text>
    <notes>
      <xsl:for-each-group select="../notes/note[@scope=current()/@scope-id]" 
			  group-adjacent="concat(@merge[.='false']/generate-id(),.)">
	<xsl:text>&#10;  </xsl:text>
	<xsl:variable name="p" select="position()"/>
	<note ref="{$p}">
	  <xsl:copy-of select="@* except (@ref,@merge),node()"/>
	</note>
	<xsl:for-each select="current-group()">
	  <xsl:text>&#10;  </xsl:text>
	  <note-ref xref="{$p}">
	    <xsl:copy-of select="@* except (@ref,@merge)"/>
	  </note-ref>
	</xsl:for-each>
      </xsl:for-each-group>
      <xsl:text>&#10;</xsl:text>
    </notes>
  </xsl:template>

</xsl:stylesheet>


$ saxon8 merg.xml merg.xsl
<?xml version="1.0" encoding="UTF-8"?><a>
<notes>
  <note ref="1" ID="1" scope="A">Some <b>text</b></note>
  <note-ref xref="1" ID="1" scope="A"/>
  <note ref="2" ID="2" scope="A">Some <b>text</b></note>
  <note-ref xref="2" ID="2" scope="A"/>
  <note ref="3" ID="3" scope="A">More</note>
  <note-ref xref="3" ID="3" scope="A"/>
  <note-ref xref="3" ID="4" scope="A"/>
</notes>
<notes>
  <note ref="1" ID="5" scope="B">More</note>
  <note-ref xref="1" ID="5" scope="B"/>
  <note-ref xref="1" ID="6" scope="B"/>
</notes></a>

________________________________________________________________________
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