xslt counting different content of the same content

谁说胖子不能爱 提交于 2019-12-06 00:30:03

Your XPath needs to change a little...

XML Input (corrected to be well formed)

<footballclub>
    <player>
        <based>international</based>
        <height>5.5</height>
        <build>medium</build>
        <age>24</age>
    </player>
    <player>
        <based>local</based>
        <height>5.5</height>
        <build>medium</build>
        <age>24</age>
    </player>
    <player>
        <based>international</based>
        <height>5.5</height>
        <build>medium</build>
        <age>24</age>
    </player>
    <player>
        <based>local</based>
        <height>5.5</height>
        <build>medium</build>
        <age>24</age>
    </player>
</footballclub>

XSLT 1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="4.0"/>

    <xsl:template match="/">
        <html>
            <head>
                <title>bombers FC</title>
            </head>
            <body>
                <p>
                    <xsl:text>NUMBER OF INTERNATIONAL PLAYERS IS: </xsl:text>
                    <xsl:value-of select="count(footballclub/player[based='international'])"/>
                </p>
                <p>
                    <xsl:text>AVERAGE HEIGHT OF INTERNATIONAL PLAYERS IS: </xsl:text>
                    <xsl:value-of select="sum(footballclub/player[based='international']/height) div count(footballclub/player[based='international'])"/>
                </p>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Output

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <title>bombers FC</title>
   </head>
   <body>
      <p>NUMBER OF INTERNATIONAL PLAYERS IS: 2</p>
      <p>AVERAGE HEIGHT OF INTERNATIONAL PLAYERS IS: 5.375</p>
   </body>
</html>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!