【发布时间】:2015-05-27 19:16:39
【问题描述】:
我有一个 xml 数据文件,其中包含大量重复字段,每个字段都与大约 10 个唯一的设施名称相关联,如下所示:
<Dailyreport>
<msg>
<msgdate>05/27/2015</msgdate>
<facility>North</facility>
<ispass>0</ispass>
</msg>
<msg>
<msgdate>05/27/2015</msgdata>
<facility>South</facility>
<ispass>1</ispass>
</msg>
</Dailyreport>
我有一个 XSL 样式表 1.0 版,我可以在其中按设施获取出现次数,如下所示:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<table style="margin-left:auto;margin-right:auto" rules="all" border="1">
<xsl:if test="Dailyreport//msg[facility='North']">
<tr><td>North Building:</td></tr>
<tr><td>Total:<xsl:value-of select="count(Dailyreport/msg[facility='North'])"/></td></tr>
<tr><td>Pass:<xsl:value-of select="count(Dailyreport/msg[facility='North' and ispass='1'])"/></td></tr>
<tr><td>Fail:<xsl:value-of select="count(DailyELRreport/msg[facility='North' and ispass='0'])"/></td></tr>
<tr><td>-------------------</td></tr>
<tr><td>
</td></tr>
</xsl:if>
</table>
</html>
</xsl:template>
</xsl:stylesheet>
但是,为了获得所有可能设施的计数,我必须使用每个设施名称重复 (xsl:if test) 部分。
我想看看我是否可以在第二个 xml 数据文件中找到设施名称并使用 document() 函数通过可能将它们加载到全局参数中来遍历它们,然后使用调用模板函数来重复调用一个 (xsl:if test) 部分。并让它使用参数值而不是固定的设施名称......就像这样:
<xsl:if test="Dailyreport//msg[facility=$sender]">
我尝试过的一切都失败了。 想知道是否有人可以提供帮助! 谢谢!
【问题讨论】:
标签: xslt-1.0