【发布时间】:2019-01-18 03:42:18
【问题描述】:
我是 xsl 的初学者,所以也许这是一个非常简单的问题。 我有一个 xsl 文件,我想在其中找到在 param-object 中定义的特定值:
<xsl:param name="locales">
<label name="testname"><locale name="de">german text</locale><locale name="en">english text</locale></label>
</xsl:param>
<xsl:template match="foo">
<topLevelElement xmlns="http://foo.bar.org">
<xsl:value-of select="ext:node-set($locales)/label[@name='testname']/locale[@name='en']"/>
</topLevelElement>
</xsl:template>
我希望得到值'english text',因为我想在参数locales 中找到名称为testname 的label。在那里我想找到一个名为en 的locale。但它不起作用。
当我用星号替换特定元素(标签和语言环境)的名称时,它会起作用:
<xsl:param name="locales">
<label name="testname"><locale name="de">german text</locale><locale name="en">english text</locale></label>
</xsl:param>
<xsl:template match="foo">
<topLevelElement xmlns="http://foo.bar.org">
<xsl:value-of select="ext:node-set($locales)/*[@name='testname']/*[@name='en']"/>
</topLevelElement>
</xsl:template>
谁能告诉我为什么我找不到孩子的名字? 非常感谢!
编辑: 该代码没有显示名称空间(我猜它是由浏览器解释的)。开头和结尾都没有括号:
xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://foo.bar.org" xmlns:ext="http://exslt.org/common" version="1.0" xsl:output method="xml" version="1.0" encoding="UTF-8"/
【问题讨论】:
-
让我猜猜:在您的 XSLT 文件中定义了一个
xmlns="..."默认命名空间。 -
是的,我有。我已经编辑了我的问题。那么它有什么问题呢?我的标签和语言环境现在是否有另一个命名空间,所以我找不到它们?
-
函数减速'ext:node-set(...)'在哪里?