0
所有元素我有以下源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模板:
<?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>
声明中的条件。请帮助我:)
UPD: 由于Saxon-HE 9.5.1.7的使用情况,xslt 2.0解决方案正常。
测试,这个工程。我的误解是选择xpath-ax而不是比较实际的前缀。 TY。 – Helvdan