gpt4 book ai didi

xslt统计相同内容的不同内容

转载 作者:行者123 更新时间:2023-12-02 03:55:13 24 4
gpt4 key购买 nike

刚开始学习xslt,想知道国际基础玩家的数量怎么算?还有就是国际球员的平均高度?

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="soccer.xslt"?>

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

已尝试以下;

count(//football/player/based[not(following::based='international')]) xslt:

<?xml version='1.0' encoding="utf-8"?>
<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 >
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>bombers FC</title>
</head>
<body>
NUMBER OF INTERNATIONAL PLAYERS IS:<xsl:value-of select="count(//football/player/based[not(following::based='international')])"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

结果应该是:国际球员人数:2

最佳答案

您的 XPath 需要稍微改变一下...

XML 输入(已更正为格式正确)

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

输出

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

关于xslt统计相同内容的不同内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12964917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com