xsl-list
[Top] [All Lists]

Re: [xsl] Combining segments by matching attributes

2009-07-14 08:31:20
This works perfectly. Thank you!

Dot

On Tue, Jul 14, 2009 at 12:01 PM, Martin 
Honnen<Martin(_dot_)Honnen(_at_)gmx(_dot_)de> wrote:
Dot Porter wrote:

<group>
 <text xml:id="A15">
   <seg n="220.2">...</seg>
   <seg n="220.3">...</seg>
   (etc.)
 </text>
 <text xml:id="B15">
   <seg n="220.2">...</seg>
   <seg n="220.3">...</seg>
   (etc.)
 </text>
</group>

The texts may or may not have all the same segments (so text A may
have seg[(_at_)n='223.1'] and text B may not, or vice versa). In addition
the numbers are not unique to each segment (there may be several segs
in a row with the same number).

Given this, I would like to generate a file that pulls together the
like segments from each text, resulting in something that looks like
this:

<app>
 <rdg wit="#A15"><seg n="220.2">...</seg></rdg>
 <rdg wit="#B15><seg n="220.2">...</seg></rdg>
 (etc.)
</app>
<app>
 <rdg wit="#A15"><seg n="220.3">...</seg></rdg>
 <rdg wit="#B15><seg n="220.3">...</seg></rdg>
 (etc.)
</app>
<app>
 <!-- for example, A15 lacks seg[(_at_)n='223.1'] -->
 <rdg wit="#B15"><seg n="223.1">...</seg></rdg>
 (etc.)
</app>

Here is an XSLT 2.0 solution:

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

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="/">
   <xsl:for-each-group select="group/text/seg" group-by="@n">
     <app>
       <xsl:apply-templates select="current-group()"/>
     </app>
   </xsl:for-each-group>
 </xsl:template>

 <xsl:template match="seg">
   <reg wit="#{../@xml:id}">
     <xsl:copy-of select="."/>
   </reg>
 </xsl:template>

</xsl:stylesheet>




--

       Martin Honnen
       http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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>
--~--





-- 
*~*~*~*~*~*~*~*~*~*~*
Dot Porter (MA, MSLS)          Metadata Manager
Digital Humanities Observatory (RIA), Regus House, 28-32 Upper
Pembroke Street, Dublin 2, Ireland
-- A Project of the Royal Irish Academy --
Phone: +353 1 234 2444        Fax: +353 1 234 2400
http://dho.ie          Email: dot(_dot_)porter(_at_)gmail(_dot_)com
*~*~*~*~*~*~*~*~*~*~*

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>