xsl-list
[Top] [All Lists]

Re: Merging Alternate readings...

2003-03-31 05:24:39

  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="{(_at_)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



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