【发布时间】:2016-02-19 16:33:06
【问题描述】:
我有以下源 xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:filter="filter_this" xmlns:also_filter="filter_also">
<filter:error>This element should be filtred</filter:error>
<ok>This is ok</ok>
<filter:error>This element should be filtred also</filter:error>
<ok>This is also ok</ok>
</root>
任务是过滤带有命名空间的元素,例如*:*。
root 元素中可能存在具有随机命名空间的元素,而不仅仅是我作为示例给出的 filter 或 also_filter。
所以想要的输出应该是这样的:
This is ok
This is also ok
我已经尝试了以下 xslt-template:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output indent="yes" method="text"/>
<xsl:template match="/">
<xsl:for-each select="/root/*">
<xsl:if test="not(namespace::*)">
<xsl:copy-of select="."/>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
给出空输出。我需要弄清楚<xsl:if...></xsl:if> 语句中的条件。请帮助我:)
更新: 由于使用 Saxon-HE 9.5.1.7,xslt 2.0 解决方案还可以。
【问题讨论】:
标签: xml xslt namespaces xslt-2.0 xml-namespaces