XSL 1.0单独分组

时间:2018-11-28 16:05:26

标签: xml xslt

我有以下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>

很抱歉,您使用的是西里尔符号。我想要的是将每个单词按FiniteForm @Tense分组。我目前正在做的是我在每个单词中循环浏览。并执行Muenchian分组。问题是我的钥匙实际上与每个FiniteForm匹配,并且我希望它仅与我所在的单词标签内的那些FiniteForm标签匹配。

这是我当前创建密钥的方式。

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

这就是我要做的。

<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>

1 个答案:

答案 0 :(得分:1)

将密钥定义为:

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

然后将其用作:

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

这会将父morph的ID添加到密钥中,以便将每个变体的形式分别分组。