使用 xpath-default-namespace 定义在 XSL XPath 中使用的默认命名空间 [英] Define a default namespace for use in XSL XPaths with xpath-default-namespace
问题描述
我有这个简单的 xml 文档:
I have this simple xml document:
<?xml version='1.0' encoding='UTF-8'?>
<registry xmlns="http://www.iana.org/assignments" id="character-sets">
<registry id="character-sets-1">
<record>
<name>ANSI_X3.4-1968</name>
</record>
</registry>
</registry>
当我使用这个 xsl 时,我可以提取名称:
When I use this xsl I can extract the name:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://www.iana.org/assignments" version="1.0">
<xsl:template match="/my:registry">
<xsl:copy-of select="//my:record/my:name"/>
</xsl:template>
</xsl:stylesheet>
但是,如果我在 xsl xpath-selectors 中省略命名空间,则不会得到任何输出:
However, If I omit the namespace in the xsl xpath-selectors, I get no output:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://www.iana.org/assignments" xpath-default-namespace="http://www.iana.org/assignments" version="1.0">
<xsl:template match="/registry">
<xsl:copy-of select="//record/name"/>
</xsl:template>
</xsl:stylesheet>
我认为 xpath-default-namespace 是用来解决问题的.我错过了什么?
I thought xpath-default-namespace is meant to do the trick. What am I missing?
如果库版本很重要,我有
In case library versions are important I have
libexpat1 (>= 1.95.8)
libexpat1 (>= 1.95.8)
libxerces-c3.1
libxerces-c3.1
libxml2 (>= 2.7.4)
libxml2 (>= 2.7.4)
libxslt1.1 (>= 1.1.25)
libxslt1.1 (>= 1.1.25)
推荐答案
不幸的是 xpath-default-namespace
是 XSLT 2.0 的一个特性.您需要在 xslt 1.0
Unfortunately xpath-default-namespace
is an XSLT 2.0 feature. You'll need to repeat the namespace or alias it in your xpath
in xslt 1.0
参考:Jenni Tennison 和 IBM
这篇关于使用 xpath-default-namespace 定义在 XSL XPath 中使用的默认命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!