【发布时间】:2008-12-04 13:49:16
【问题描述】:
我需要解析 Visual Studio 自动生成的 XML 文档来创建报告。我决定使用 XSLT,但我对它很陌生,需要帮助。 常用模板为:
<doc>
<members>
<member name="F:MyNamespace">
<summary>Some text</summary>
</member>
</members>
</doc>
我想隔离名称以某个单词开头的成员,例如 P:Interfaces.Core。我决定在 select 语句中使用 RegExp。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/TR/xpath-functions/">
<xsl:template match="/" >
<html xmlns="http://www.w3.org/1999/xhtml">
<body style="font-family:Tahoma">
<p>Interfaces list:</p>
<table>
<xsl:for-each select="doc/members/member">
<xsl:sort order="ascending" />
<xsl:value-of select="fn:matches(., 'P\..+')" />
<br />
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
为什么会出错:
命名空间http://www.w3.org/TR/xpath-functions不包含任何函数>
我哪里错了?我在示例中找到了这样的代码,包括 w3c.org!
【问题讨论】:
-
Abatishchev,看我的回答。在此时的所有答案中,只有这一个为您提供了要使用的确切 XPath 表达式。它还讨论了其他可用选项,演示了其他可用 XPath 1.0 函数的使用以及如何将 ends-with() 实现为 XPath 1.0 表达式。干杯