【发布时间】:2018-10-07 10:36:41
【问题描述】:
我在尝试引用的 xml 文件中的默认命名空间有问题。有谁知道这个默认的 ns 给我带来了如此多的悲伤。我已经束手无策了!
输入XML
<?xml version="1.0" encoding="utf-8"?>
<contactBatchResponse version="1.0.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="/somelocation.xsd"
xmlns="http://www.somecompany.com">
<FileStatus>
<someStatus>get status</someStatus>
</FileStatus>
</contactBatchResponse>
我不正确的 xslt :(
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="/somelocation.xsd"
xmlns="http://www.somecompany.com"
exclude-result-prefixes="#default xsi xsl ">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<Foo>
<xsl:value-of select="//someStatus"/>
</Foo>
</xsl:template>
</xsl:stylesheet>
当我运行它时,我没有为 Foo 返回任何东西,但是一旦我删除了默认命名空间,一切都很好。我在这里错过了什么????
谢谢
【问题讨论】:
-
搜索“XSLT 默认命名空间”可找到此问题的 641 个先前答案。
标签: xml xslt xpath namespaces