【发布时间】:2017-08-12 05:55:32
【问题描述】:
XPATH/XSLT 1.0 是否可以选择所有以“Foo”结尾的属性?
我正在编写一些 XSLT 来获取属性名称以“Foo”结尾的所有“InterestingElement”的所有属性的所有值的列表。
其实我也想过滤掉那些值为空的""
我尝试为 XSLT 2.0 指定样式表,但得到了xsl:version: only 1.0 features are supported:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
到目前为止我有:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:for-each select="//InterestingElement">
<xsl:value-of select="__what goes here?__"/><xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:text>end</xsl:text>
</xsl:template>
</xsl:stylesheet>
这里有一些示例 XML:
<?xml version="1.0"?>
<root>
<Other Name="Bob"/>
<InterestingElements>
<InterestingElement AttrFoo="want this"
Attr2Foo="this too"
Blah="not this"
NotThisFoo=""/>
</InterestingElements>
</root>
【问题讨论】:
-
XSLT 1.0 还是 2.0?
-
你也可以分享
xml示例、所需的输出和你已经尝试过的代码吗?