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

Applying templates for unique children

Subject: Applying templates for unique children
From: Elizabeth Barham <lizzy@xxxxxxxxxxxxxxxxx>
Date: 04 Aug 2003 15:06:12 -0500
xsl key unique
Hi,

   Consider this:

  <root>
    <sequence>carcin</sequence>
    <combining-vowel>o</combining-vowel>
    <definition xml:lang="en">cancer</definition>
  </root>
  <root>
    <sequence>carcin</sequence>
    <combining-vowel>o</combining-vowel>
    <definition xml:lang="en">cancer</definition>
    <definition xml:lang="en">cancerous</definition>
  </root>
  <root>
    <sequence>carcin</sequence>
    <combining-vowel>o</combining-vowel>
    <definition xml:lang="en">cancerous, cancer</definition>
  </root>

  With the goal of turning it into:

  <root>
    <sequence>carcin</sequence>
    <combining-vowel>o</combining-vowel>
    <definition xml:lang="en">cancer</definition>
    <definition xml:lang="en">cancerous</definition>
    <definition xml:lang="en">cancerous, cancer</definition>
  </root>

I'm using the Muenchian grouping method to select the first <root> element
with the same <sequence>:

   <xsl:key name="root-key" match="root" use="sequence"/>

and

      <xsl:for-each select="root[generate-id() = generate-id(key('root-key', sequence)[1])]">
	<xsl:apply-templates select="."/>
      </xsl:for-each>

Which is great because the matching template is called once for each
unique <sequence>, but the kicker is the group of <definition>'s that
much be unique as well. So far, this is what I have:

  <xsl:template match="root">
    <xsl:copy>
      <xsl:apply-templates select="sequence | combining-vowel"/>
      <xsl:for-each select="key('root-key', sequence)/definition">
	<xsl:sort />
	<xsl:apply-templates select="."/>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

Which applies the template on *all* definitions for a the matching
root/sequence, not simply the unique one.

   Why don't I just use the Muenchian method again? Because there are
<definition> elements that have the same value under a different
root/sequence so the first element in the key may not be the same as
the one in the current node, e.g.:

  <xsl:key name="definition-key" match="definition" use="."/>

   If I filter on the first element of definition-key, as in:

      <xsl:for-each select="key('root-key', sequence)/definition[generate-id() = generate-id(key('definition-key', .)[1])]">
	<xsl:sort />
	<xsl:apply-templates select="."/>
      </xsl:for-each>

There may be *no* match because, as an example, there may have been
this before the "carcin" elements used in the first example:

  <root>
    <sequence>anything</sequence>
    <combining-vowel>a</combining-vowel>
    <definition xml:lang="en">cancer</definition>
  </root>

Any ideas on how to solve this?

Thank you,
Elizabeth

 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.