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

Re: Merging Alternate readings...

Subject: Re: Merging Alternate readings...
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 31 Mar 2003 13:24:39 +0100
alternate readings
  I'm assuming it somehow involves an xsl:for-each based on the contents of
  body/@wit to create an individual reading for each of these IDREFS,
  but then how do you merge the duplicate ones back together?

yes exactly.
If you do the first pass first then merging the things is a standard
grouping problem. the solution below uses saxon:node-set to do two
passes in a single stylesheet, and also to get a variable that contains
the list of ids over which to iterate. (If one id could be a substring
of another the contains() test would need to be a bit more careful
eg by concatenating a space before testing for teh substring).




$ saxon wit.xml wit.xsl
<?xml version="1.0" encoding="utf-8"?>
<foo>

   <a id="a1">
      <body wit="A C D">This is a test, really.</body>
      <body wit="B E">This is a testament, really.</body>
      <body wit="F"/>
   </a>

   <a id="a2">
      <body wit="A">This is a test, a really long test!</body>
      <body wit="B C">This is a testament, a really important test!</body>
      <body wit="D">This is a test, a really boringtest!</body>
      <body wit="E">This is a testament, a really long test!</body>
      <body wit="F">This is a different body element</body>
   </a>

</foo>




<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" 
xmlns:saxon="http://icl.com/saxon"
                extension-element-prefixes="saxon"

>

<xsl:output indent="yes"/>

<xsl:variable name="wits">
<x>A</x>
<x>B</x>
<x>C</x>
<x>D</x>
<x>E</x>
<x>F</x>
</xsl:variable>

<xsl:template match="foo">
<foo>
<xsl:apply-templates/>
</foo>
</xsl:template>


<xsl:key name="k" match="body" use="."/>

<xsl:template match="a">
<a id="{@id}">
<xsl:variable name="a" select="."/>
<xsl:variable name="one">
<xsl:for-each select="saxon:node-set($wits)/*">
<body wit="{.}">
  <xsl:variable name="x">
  <xsl:apply-templates mode="wit" select="$a/node()">
     <xsl:with-param name="wit" select="."/>
  </xsl:apply-templates>
  </xsl:variable>
  <xsl:value-of select="normalize-space($x)"/>
</body>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="saxon:node-set($one)/*">
<xsl:if test="generate-id(.)=generate-id(key('k',.))">
<body>
<xsl:attribute name="wit">
<xsl:for-each select="key('k',.)">
<xsl:value-of select="@wit"/>
<xsl:if test="position()&lt;last()"><xsl:text> </xsl:text></xsl:if>
</xsl:for-each>
</xsl:attribute>
<xsl:value-of select="."/>
</body>
</xsl:if>

</xsl:for-each>
</a>
</xsl:template>


<xsl:template mode="wit" match="*">
<xsl:param name="wit"/>
<xsl:if test="not(@wit) or (@wit and contains(@wit,$wit))">
<xsl:apply-templates mode="wit">
  <xsl:with-param name="wit" select="$wit"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. 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
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.