D.Dimov
D.Dimov

Reputation: 53

XSL 1.0 separate grouping

I have the following XML.

<word>
    <lemma POS="глагол" Aspect="несвършен"  Transitive= "непреходен">викам</lemma>
    <morph>
      <FiniteForm Tense="present" Person="1" Number="ед.ч.">викам</FiniteForm>
      <FiniteForm Tense="present" Person="2" Number="ед.ч.">викаш</FiniteForm>
      <FiniteForm Tense="present" Person="3" Number="ед.ч.">вика</FiniteForm>
      <FiniteForm Tense="past_simple" Person="2" Number="ед.ч.">вика</FiniteForm>
      <FiniteForm Tense="past_simple" Person="3" Number="ед.ч.">вика</FiniteForm>
      <FiniteForm Tense="past_continues" Person="1" Number="ед.ч.">виках</FiniteForm>
      <FiniteForm Tense="past_continues" Person="2" Number="ед.ч.">викаше</FiniteForm>
      <FiniteForm Tense="past_continues" Person="3" Number="ед.ч.">викаше</FiniteForm>
   </morph>
</word>
<word>
    <lemma POS="глагол" Aspect="несвършен"  Transitive= "непреходен">вървя</lemma>
    <morph>
      <FiniteForm Tense="present" Person="1" Number="ед.ч.">вървя</FiniteForm>
      <FiniteForm Tense="present" Person="2" Number="ед.ч.">вървиш</FiniteForm>
      <FiniteForm Tense="present" Person="3" Number="ед.ч.">вървят</FiniteForm>
      <FiniteForm Tense="past_simple" Person="2" Number="ед.ч.">вървят</FiniteForm>
      <FiniteForm Tense="past_simple" Person="3" Number="ед.ч.">вървя</FiniteForm>
      <FiniteForm Tense="past_continues" Person="1" Number="ед.ч.">вървях</FiniteForm>
      <FiniteForm Tense="past_continues" Person="2" Number="ед.ч.">вървеше</FiniteForm>
      <FiniteForm Tense="past_continues" Person="3" Number="ед.ч.">вървеше</FiniteForm>
   </morph>
</word>

Sorry for the cyrilic symbols. What I want is to group this by FiniteForm @Tense for each word. What I am currently doing is I am looping through each word. And performing Muenchian grouping. The problem is that my key actually matches every FiniteForm and I want it to match only those FiniteForm tags inside the word tag I am in.

This is how I create the key currently.

<xsl:key name="finiteFormsByTense" match="FiniteForm" use="@Tense" />

And this is what I do.

<xsl:for-each select="word">
<xsl:for-each select="morph/FiniteForm[generate-id() = generate-id(key('finiteFormsByTense', @Tense)[1])]">
    <xsl:variable name="current-grouping-key" select="@Tense"/>
    <xsl:variable name="current-group" select="key('finiteFormsByTense', $current-grouping-key)"/>
    <xsl:variable select="count($current-group)+1" name="groupSize"/>
    <tr>
        <td rowspan="{$groupSize}">
            <xsl:value-of select="$current-grouping-
        </td>
    </tr>
    <xsl:for-each select="$current-group">
        <tr>
            <td><xsl:value-of select="@Person"/></td>
            <td><xsl:value-of select="@Number"/></td>
            <td><xsl:value-of select="."/></td>
        </tr>
</xsl:for-each>
</xsl:for-each>

Upvotes: 0

Views: 37

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117083

Define your key as:

<xsl:key name="finiteFormsByTense" match="FiniteForm" use="concat(generate-id(..), '|', @Tense)" />

Then use it as:

<xsl:for-each select="morph/FiniteForm[generate-id() = generate-id(key('finiteFormsByTense', concat(generate-id(..), '|', @Tense))[1])]">

This adds the id of the parent morph to the key, so that the forms of each morph are grouped separately .

Upvotes: 1

Related Questions