[xsl] Combining segments by matching attributes

Subject: [xsl] Combining segments by matching attributes
From: Dot Porter <dot.porter@xxxxxxxxx>
Date: Tue, 14 Jul 2009 11:32:12 +0100
Dear List,

I'm having an issue and I'm not even sure where to start.

I have a document in TEI consisting of a group of several versions of
the same text, divided into segments (<seg>) and numbered (@n). The
numbering is the same in all versions (so <seg n="220.2"> is the same
in text A as in text B). The general structure is:

<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[@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[@n='223.1'] -->
  <rdg wit="#B15"><seg n="223.1">...</seg></rdg>
  (etc.)
</app>

I suppose this can be done by matching the values of @n (those segs
have the same @n one after the other might be dealt with by counting,
or I could handle them by hand as they aren't numerous). I just have
no idea even where to start with this. My XSLT skills aren't bad but I
don't have too much experience using it to rearrange XML into new
structures.

Any suggestions would be most appreciated!

Dot

-- 
*~*~*~*~*~*~*~*~*~*~*
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.porter@xxxxxxxxx
*~*~*~*~*~*~*~*~*~*~*

Current Thread