Xml 知道谁';使元素具有更多子节点

Xml 知道谁';使元素具有更多子节点,xml,xslt,xsd,Xml,Xslt,Xsd,我在XML文档中添加了一个votation。我得知道投票多了有什么建议,我怎么做? 我正在用XSLT进行转换,但我找不到一种方法来实现这一点 XML: 50%的valor接受了调查 20%的valor接受了调查 在本例中,第一个描述应该是winner propose。在XSLT 2.0中,您可以对每个组使用带有排序的标记。下面是XSLT <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="

我在XML文档中添加了一个votation。我得知道投票多了有什么建议,我怎么做? 我正在用XSLT进行转换,但我找不到一种方法来实现这一点

XML:


50%的valor接受了调查
20%的valor接受了调查

在本例中,第一个描述应该是winner propose。

在XSLT 2.0中,您可以对每个组使用带有排序的
标记。下面是XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="2.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:template match="/tns:vote/tns:alternative">

    <xsl:for-each-group select="*" group-starting-with="tns:description">
      <xsl:sort select="count(current-group()[2]/tns:member_vote)" order="descending"/>

      <xsl:if test="position() = 1">

        <tns:winning_alternative vote_count="{count(current-group()[2]/tns:member_vote)}>
          <xsl:copy-of select="current-group()"/>
        </tns:winning_alternative>

      </xsl:if>

    </xsl:for-each-group>
  </xsl:template>
</xsl:stylesheet>


在XSLT2.0中,可以对每个组使用
标记和
排序
。下面是XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="2.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:template match="/tns:vote/tns:alternative">

    <xsl:for-each-group select="*" group-starting-with="tns:description">
      <xsl:sort select="count(current-group()[2]/tns:member_vote)" order="descending"/>

      <xsl:if test="position() = 1">

        <tns:winning_alternative vote_count="{count(current-group()[2]/tns:member_vote)}>
          <xsl:copy-of select="current-group()"/>
        </tns:winning_alternative>

      </xsl:if>

    </xsl:for-each-group>
  </xsl:template>
</xsl:stylesheet>


在XSLT2.0中,可以对每个组使用
标记和
排序
。下面是XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="2.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:template match="/tns:vote/tns:alternative">

    <xsl:for-each-group select="*" group-starting-with="tns:description">
      <xsl:sort select="count(current-group()[2]/tns:member_vote)" order="descending"/>

      <xsl:if test="position() = 1">

        <tns:winning_alternative vote_count="{count(current-group()[2]/tns:member_vote)}>
          <xsl:copy-of select="current-group()"/>
        </tns:winning_alternative>

      </xsl:if>

    </xsl:for-each-group>
  </xsl:template>
</xsl:stylesheet>


在XSLT2.0中,可以对每个组使用
标记和
排序
。下面是XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="2.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

  <xsl:template match="/tns:vote/tns:alternative">

    <xsl:for-each-group select="*" group-starting-with="tns:description">
      <xsl:sort select="count(current-group()[2]/tns:member_vote)" order="descending"/>

      <xsl:if test="position() = 1">

        <tns:winning_alternative vote_count="{count(current-group()[2]/tns:member_vote)}>
          <xsl:copy-of select="current-group()"/>
        </tns:winning_alternative>

      </xsl:if>

    </xsl:for-each-group>
  </xsl:template>
</xsl:stylesheet>


在xslt 1.0中,可以使用xsl:sort指令,如:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tns="tns">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <result>
            <xsl:apply-templates select="tns:vote/tns:alternative" />
        </result>
    </xsl:template>

    <xsl:template match="tns:alternative">
        <!-- Process all description -->
        <xsl:for-each select="tns:description">
            <!-- Sort them descending by count votes in the first following sibling tns:votes -->
            <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending" />
            <!-- Do anything with that, e.g. make a deep copy -->
            <xsl:copy-of select="." />
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

它生成描述按投票数降序排列的xml


如果您只需要一个值(“获胜者”),您可以使用例如,
..
内部的每个值。

在xslt 1.0中,您可以使用xsl:sort指令,如:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tns="tns">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <result>
            <xsl:apply-templates select="tns:vote/tns:alternative" />
        </result>
    </xsl:template>

    <xsl:template match="tns:alternative">
        <!-- Process all description -->
        <xsl:for-each select="tns:description">
            <!-- Sort them descending by count votes in the first following sibling tns:votes -->
            <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending" />
            <!-- Do anything with that, e.g. make a deep copy -->
            <xsl:copy-of select="." />
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

它生成描述按投票数降序排列的xml


如果您只需要一个值(“获胜者”),您可以使用例如,
..
内部的每个值。

在xslt 1.0中,您可以使用xsl:sort指令,如:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tns="tns">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <result>
            <xsl:apply-templates select="tns:vote/tns:alternative" />
        </result>
    </xsl:template>

    <xsl:template match="tns:alternative">
        <!-- Process all description -->
        <xsl:for-each select="tns:description">
            <!-- Sort them descending by count votes in the first following sibling tns:votes -->
            <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending" />
            <!-- Do anything with that, e.g. make a deep copy -->
            <xsl:copy-of select="." />
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

它生成描述按投票数降序排列的xml


如果您只需要一个值(“获胜者”),您可以使用例如,
..
内部的每个值。

在xslt 1.0中,您可以使用xsl:sort指令,如:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tns="tns">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <result>
            <xsl:apply-templates select="tns:vote/tns:alternative" />
        </result>
    </xsl:template>

    <xsl:template match="tns:alternative">
        <!-- Process all description -->
        <xsl:for-each select="tns:description">
            <!-- Sort them descending by count votes in the first following sibling tns:votes -->
            <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending" />
            <!-- Do anything with that, e.g. make a deep copy -->
            <xsl:copy-of select="." />
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

它生成描述按投票数降序排列的xml


如果您只需要一个值(“获胜者”),您可以为每个值使用

此解决方案结合@Jirka的XSLT 1.0方法和我对多个最佳投票的评论,并简单地输出所有最佳投票的列表。它使用一个准备步骤来确定最佳票数,然后在第二步中选择具有最佳票数的所有票数。请注意,在第二步中,我们不再需要排序。如果需要的话,我们仍然可以做一些事情,如果有另一个合理的标准打破最佳选票的对称性

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="1.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:strip-space elements="*"/>

  <xsl:template match="/tns:vote/tns:alternative">

    <!-- compute the best vote count; just the number not the elements -->
    <xsl:variable name="best_vote">
      <xsl:for-each select="tns:description">
        <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending"/>
        <xsl:if test="position() = 1">
          <xsl:value-of select="count(following-sibling::tns:votes[1]/tns:member_vote)"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>

    <tns:result>
      <xsl:for-each select="tns:description"> <!-- we need not sort here anymore! -->

        <!-- only dump those entries which match the best vote count -->
        <xsl:if test="count(following-sibling::tns:votes[1]/tns:member_vote) = number($best_vote)">

          <tns:winning_vote vote_count="{count(following-sibling::tns:votes[1]/tns:member_vote)}">
            <xsl:copy-of select="."/>
            <xsl:copy-of select="following-sibling::tns:votes[1]/tns:member_vote"/>
          </tns:winning_vote>

        </xsl:if>

      </xsl:for-each>
    </tns:result>
  </xsl:template>
</xsl:stylesheet>

此解决方案结合了@Jirka的XSLT1.0方法和我关于多个最佳投票的评论,只输出所有最佳投票的列表。它使用一个准备步骤来确定最佳票数,然后在第二步中选择具有最佳票数的所有票数。请注意,在第二步中,我们不再需要排序。如果需要的话,我们仍然可以做一些事情,如果有另一个合理的标准打破最佳选票的对称性

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="1.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:strip-space elements="*"/>

  <xsl:template match="/tns:vote/tns:alternative">

    <!-- compute the best vote count; just the number not the elements -->
    <xsl:variable name="best_vote">
      <xsl:for-each select="tns:description">
        <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending"/>
        <xsl:if test="position() = 1">
          <xsl:value-of select="count(following-sibling::tns:votes[1]/tns:member_vote)"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>

    <tns:result>
      <xsl:for-each select="tns:description"> <!-- we need not sort here anymore! -->

        <!-- only dump those entries which match the best vote count -->
        <xsl:if test="count(following-sibling::tns:votes[1]/tns:member_vote) = number($best_vote)">

          <tns:winning_vote vote_count="{count(following-sibling::tns:votes[1]/tns:member_vote)}">
            <xsl:copy-of select="."/>
            <xsl:copy-of select="following-sibling::tns:votes[1]/tns:member_vote"/>
          </tns:winning_vote>

        </xsl:if>

      </xsl:for-each>
    </tns:result>
  </xsl:template>
</xsl:stylesheet>

此解决方案结合了@Jirka的XSLT1.0方法和我关于多个最佳投票的评论,只输出所有最佳投票的列表。它使用一个准备步骤来确定最佳票数,然后在第二步中选择具有最佳票数的所有票数。请注意,在第二步中,我们不再需要排序。如果需要的话,我们仍然可以做一些事情,如果有另一个合理的标准打破最佳选票的对称性

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="1.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:strip-space elements="*"/>

  <xsl:template match="/tns:vote/tns:alternative">

    <!-- compute the best vote count; just the number not the elements -->
    <xsl:variable name="best_vote">
      <xsl:for-each select="tns:description">
        <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending"/>
        <xsl:if test="position() = 1">
          <xsl:value-of select="count(following-sibling::tns:votes[1]/tns:member_vote)"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>

    <tns:result>
      <xsl:for-each select="tns:description"> <!-- we need not sort here anymore! -->

        <!-- only dump those entries which match the best vote count -->
        <xsl:if test="count(following-sibling::tns:votes[1]/tns:member_vote) = number($best_vote)">

          <tns:winning_vote vote_count="{count(following-sibling::tns:votes[1]/tns:member_vote)}">
            <xsl:copy-of select="."/>
            <xsl:copy-of select="following-sibling::tns:votes[1]/tns:member_vote"/>
          </tns:winning_vote>

        </xsl:if>

      </xsl:for-each>
    </tns:result>
  </xsl:template>
</xsl:stylesheet>

此解决方案结合了@Jirka的XSLT1.0方法和我关于多个最佳投票的评论,只输出所有最佳投票的列表。它使用一个准备步骤来确定最佳票数,然后在第二步中选择具有最佳票数的所有票数。请注意,在第二步中,我们不再需要排序。如果需要的话,我们仍然可以做一些事情,如果有另一个合理的标准打破最佳选票的对称性

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="1.0"
    xmlns:tns="mynamespace"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:strip-space elements="*"/>

  <xsl:template match="/tns:vote/tns:alternative">

    <!-- compute the best vote count; just the number not the elements -->
    <xsl:variable name="best_vote">
      <xsl:for-each select="tns:description">
        <xsl:sort select="count(following-sibling::tns:votes[1]/tns:member_vote)" order="descending"/>
        <xsl:if test="position() = 1">
          <xsl:value-of select="count(following-sibling::tns:votes[1]/tns:member_vote)"/>
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>

    <tns:result>
      <xsl:for-each select="tns:description"> <!-- we need not sort here anymore! -->

        <!-- only dump those entries which match the best vote count -->
        <xsl:if test="count(following-sibling::tns:votes[1]/tns:member_vote) = number($best_vote)">

          <tns:winning_vote vote_count="{count(following-sibling::tns:votes[1]/tns:member_vote)}">
            <xsl:copy-of select="."/>
            <xsl:copy-of select="following-sibling::tns:votes[1]/tns:member_vote"/>
          </tns:winning_vote>

        </xsl:if>

      </xsl:for-each>
    </tns:result>
  </xsl:template>
</xsl:stylesheet>


我需要XSLT1.0:sI需要XSLT1.0:sI需要XSLT1.0:sI需要XSLT1.0:sI需要XSLT1.0:s