[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Combining segments by matching attributes

Subject: Re: Combining segments by matching attributes
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 14 Jul 2009 13:01:53 +0200
Re:  Combining segments by matching attributes
Dot Porter wrote:

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

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

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

Here is an XSLT 2.0 solution:


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

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

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



	Martin Honnen

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.