Re: [xsl] Grouping - starting with certain element and ending before certain elements

Subject: Re: [xsl] Grouping - starting with certain element and ending before certain elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 5 Oct 2005 13:19:34 +0100
You no doubt could do this with for-each-group, but I think it's
probably easier in this case to use an apply-templates along the
following-sibling axis, which as it happens would also work in xslt1.

something like:



 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="2.0">

<xsl:output indent="yes"/>

<xsl:template match="dict">
  <dict>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="*"/>
  </dict>
</xsl:template>

<xsl:template match="entry">
  <entry>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="*[1]"/>
  </entry>
</xsl:template>

<xsl:template match="entry/*">
 <xsl:copy-of select="."/>
  <xsl:apply-templates select="following-sibling::*[1]"/>
</xsl:template>

<xsl:template match="entry/IDM" priority="2">
 <phrase>
 <xsl:copy-of select="."/>
  <xsl:apply-templates select="following-sibling::*[1]" mode="phrase"/>
 </phrase>
  <xsl:apply-templates select="following-sibling::*[self::IDM or self::LV2 or self::LV3][1]"/>
</xsl:template>


<xsl:template match="*" mode="phrase">
 <xsl:copy-of select="."/>
  <xsl:apply-templates select="following-sibling::*[1]" mode="phrase"/>
</xsl:template>

<xsl:template match="IDM|LV2|LV3" mode="phrase"/>

 
</xsl:stylesheet>


$ saxon8 group.xml  group.xsl
<?xml version="1.0" encoding="UTF-8"?>
<dict>
   <entry id="000152">
      <HWD>ace</HWD>
      <LV2>I</LV2>
      <PSA>n</PSA>
      <LV3>1</LV3>
      <TSL>ess</TSL>
      <phrase>
         <IDM>~ of hearts</IDM>
         <TSL>hj@qrteress</TSL>
      </phrase>
      <phrase>
         <IDM>have an ~ up one's sleeve</IDM>
         <SEA>bildl.</SEA>
         <TSL>ha trumf p@Q hand</TSL>
      </phrase>
      <LV3>2</LV3>
      <phrase>
         <IDM>within an ~ of</IDM>
         <TSL>ytterst n@qra</TSL>
         <EXA>within an ~ of victory</EXA>
      </phrase>
      <LV3>3</LV3>
      <TSL>ess</TSL>
      <LV3>4</LV3>
      <SEA>i tennis</SEA>
      <TSL>serveess</TSL>
      <phrase>
         <IDM>She has already hit 13 ~s</IDM>
         <TSL>Hon hade redan tagit 13 serveess</TSL>
      </phrase>
      <LV2>II</LV2>
      <PSA>attr adj</PSA>
      <phrase>
         <IDM>~ reporter</IDM>
         <TSL>stj@qrnreporter</TSL>
      </phrase>
   </entry>
</dict>

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread