XSL如何根据值计算节点数而不使用属性且不区分大小写
我最近开始学习XSL。我想用它来将我的 xml 文件转换为 html 文件。我要提取的数据应该显示有多少节点具有一定的价值。
XML 具有以下结构:
<Tests>
<Test>
<TestName> a </TestName>
<Date> 12.11.10 </Date>
<Result> Pass</Result>
</Test>
<Test>
<TestName> b </TestName>
<Date> 13.11.10 </Date>
<Result> Fail </Result>
</Test>
<Test>
<TestName> c </TestName>
<Date> 14.11.10 </Date>
<Result> Pass </Result>
</Test>
</Tests>
对于此 xml,我得到的输出为 --> 2(通过次数) 1(失败次数)
xsl 对于上述 xml::
<xsl:key name="kTestByResult" match="Test" use="normalize-space(Result)"/>
<xsl:template match="/">
<xsl:value-of select="concat(count(key
('kTestByResult','Fail')),' (number of Fails) ',
count(key'kTestByResult','Pass')),'(number of Passes)')"/>
</xsl:template>
这里通过可能是(通过/通过/通过)。 在任何情况下我都希望结果为 2 Passes。
有什么想法吗???
I have recently started to study XSL. I would like to use it to transform my xml file into html one. The data that I want to extract should present how many nodes have certain value.
XML has following structure:
<Tests>
<Test>
<TestName> a </TestName>
<Date> 12.11.10 </Date>
<Result> Pass</Result>
</Test>
<Test>
<TestName> b </TestName>
<Date> 13.11.10 </Date>
<Result> Fail </Result>
</Test>
<Test>
<TestName> c </TestName>
<Date> 14.11.10 </Date>
<Result> Pass </Result>
</Test>
</Tests>
For this xml I got output as --> 2 (number of Passes) 1 (number of Fails)
xsl for the above xml::
<xsl:key name="kTestByResult" match="Test" use="normalize-space(Result)"/>
<xsl:template match="/">
<xsl:value-of select="concat(count(key
('kTestByResult','Fail')),' (number of Fails) ',
count(key'kTestByResult','Pass')),'(number of Passes)')"/>
</xsl:template>
Here the pass might be (PASS/pass/Pass).
At any situation I want the result as 2 Passes.
any give some idea for this???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将大写字符转换为小写:
Translate up-case characters to low-case:
试试这个:
这会将所有值转换为大写,然后将大写“PASS”或“FAIL”传递给关键函数。
Try this:
That'll convert all values to upper case, and then just pass the uppercase 'PASS' or 'FAIL' to the key function.
这是一个更通用的解决方案,它列出了
Result
的所有不同值的计数,而不对其进行硬编码 - 例如,如果 XML 文档发生更改,结果会被跳过或 INDECISIVE,这些新值也将被列出并计数:当应用于提供的 XML 文档时:
生成所需的正确结果:
II。产生相同结果的 XSLT 2.0 解决方案:
This is a more general solution that lists the count of all distinct values of
Result
without hardcoding them -- for example, if the XML document is changed so that there are results SKIP or INDECISIVE, these new values will also be listed and counted:when applied to the provided XML document:
the wanted, correct result is produced:
II. An XSLT 2.0 solution that produces the same result: