I can't tell you why your code is slow without seeing your code.
 
You haven't specified your problem very precisely (one example isn't really enough, and I'm assuming that the absence of 1236 and the duplication of 1237 in your output is a typo). But assuming you are always handling the <alert> elements in groups of three, the normal approach would be:
 
<xsl:for-each select="alert[position() mod 3 = 1]">
  <alert ID="{@ID}">
   <newStuff>
     <xsl:value-of select="following-sibling::alert[1]/@ID"/>
     <xsl:text> </xsl:text>
     <xsl:value-of select="following-sibling::alert[2]/@ID"/>
  </newStuff>
 </alert>
</xsl:for-each>
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Donna Meyers
Sent: 03 February 2007 20:11
To: Mailing list for SAXON XSLT queries
Subject: [saxon] many-to-1 transformation

I would like to transform a XML document that has 6 elements (for example):

<message>
  <alert ID="1234">
...
  </alert>

  <alert ID="1235">
...
  </alert>

  <alert ID="1236">
...
  </alert>

  <alert ID="1237">
...
  </alert>

  <alert ID="1238">
...
  </alert>

  <alert ID="1239">
...
  </alert>
</message>

into a document that has 2 (for example):

<message>
  <alert ID="1234">
    <newStuff>1235 1237<newStuff>
  </alert>

  <alert ID="1237">
     <newStuff>1238 1239<newStuff>
  </alert>
</message>

This is a many-to-1 transformation. I have a working stylesheet to do this, but it is taking FAR TOO LONG. Is there an easy way to achieve this?

Thanks-
donna