Xml 如何选择元素,然后使用xslt中的另一个元素对它们进行排序?

Xml 如何选择元素,然后使用xslt中的另一个元素对它们进行排序?,xml,xslt,Xml,Xslt,我是XSLT2.0新手。我不确定我的问题是否准确 这是xml文件: <movies> <movie> <actor>actor 1</actor> <actor>actor 2</actor> <actor>actor 3</actor> <name>movie 1</name> <year>1997</year&g

我是XSLT2.0新手。我不确定我的问题是否准确

这是xml文件:

<movies>
  <movie>
    <actor>actor 1</actor>
    <actor>actor 2</actor>
    <actor>actor 3</actor>
    <name>movie 1</name>
    <year>1997</year>
  </movie>
  <movie>
    <actor>actor 1</actor>
    <actor>actor 4</actor>
    <actor>actor 5</actor>
    <name>movie 2</name>
    <year>1997</year>
  </movie>
  <movie>
    <actor>actor 1</actor>
    <actor>actor 6</actor>
    <actor>actor 7</actor>
    <name>movie 3</name>
    <year>1995</year>
  </movie>
  <mockumentary>
    <actor>actor 1</actor>
    <actor>actor 8</actor>
    <actor>actor 9</actor>
    <name>movie 4</name>
    <year>2000</year>
  </mockumentary>
  <mockumentary>
    <actor>actor 1</actor>
    <actor>actor 10</actor>
    <actor>actor 11</actor>
    <name>movie 5</name>
    <year>1997</year>
  </mockumentary>
</movies>

演员1
演员2
演员3
电影一
1997
演员1
演员4
演员5
电影2
1997
演员1
演员6
演员7
电影3
1995
演员1
演员8
演员9
电影4
2000
演员1
演员10
演员11
电影5
1997
以下是我迄今为止所做的:

<xsl:template match="/">
  <xsl:variable name="document" select="."/>
  <xsl:for-each select="distinct-values(//actor)">
    <xsl:variable name="actor-value"> <xsl:value-of select="."/> </xsl:variable>
    <xsl:result-document href="{concat($file-name, '.html')}">
    <html>
    <body>
      <!--selects all movie names where the current actor plays-->
      <xsl:apply-templates select="$document//name[../actor=$actor-value]" >
    <xsl:sort select="../year" order="descending" />
    <xsl:sort select="../name" />
  </xsl:apply-templates>
    </body>
    </html>
    </xsl:result-document> 
  </xsl:for-each>
</xsl:template>

<xsl:template match="name">
  <tr><th colspan="3"><xsl:value-of select="../year"/></th></tr>
  <tr>
   <!-- i call here a certain template that lists all actors -->
   <xsl:text> , </xsl:text>
   <xsl:value-of select="../name"/>
  </tr>
</xsl:template>

, 
为actor 1生成的html文件看起来有点像这样:

我想做的是为每个参与者创建一个html文件。它应该包含他演过的所有电影。电影应该按年份排序,然后按名称排序。换句话说,如果一个演员在同一年的两部电影中扮演角色,那么他们应该按照电影的名称进行排序。例如,我试图为“actor 1.html”提供类似的内容:

注意电影1、2和5应该按名字的字母顺序排列

我正在尝试按元素年选择这些电影:“$document//name[../actor=$actor value]”,然后对每一部电影进行排序,但我似乎不知道如何选择


谁能告诉我怎么做吗。谢谢大家!

有了这个,我终于找到了它

我曾经为每个小组按年度对不同的电影进行分组

以下是新代码:

<xsl:template match="/">
  <xsl:variable name="document" select="."/>
  <xsl:for-each select="distinct-values(//actor)">
    <xsl:variable name="actor-value"> <xsl:value-of select="."/> </xsl:variable>
    <xsl:result-document href="{concat($file-name, '.html')}">
    <html>
    <body>
      <p>
      <table>

        <xsl:for-each-group select="$document//name[../actor=$actor-value]" group-by="../year">
    <!--************** SORT BY YEAR **************-->
        <xsl:sort select="../year" data-type="number" order="descending"/>
        <tr><th><xsl:value-of select="../year"/></th></tr>

      <xsl:apply-templates select="current-group()" >
        <!--************** SORT BY TITLE **************-->
        <xsl:sort select="." data-type="text" order="ascending" />
      </xsl:apply-templates>
      </table>
      </p>
      </body>
      </html>
      </xsl:result-document> 
  </xsl:for-each>
</xsl:template>