XSLT 属性与命名空间匹配
对于为什么这里的第二个示例有效但第一个示例不起作用,我找不到一个很好的解释:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsd"
version="2.0">
<xsl:template match="/">
<xsl:value-of select="/wsdl:definitions/wsdl:message[@name = $messageName]"/>
<xsl:value-of select="/wsdl:definitions/wsdl:message/@name[. = $messageName]"/>
</xsl:template>
</xsl:stylesheet>
上下文正在 WSDL 文档中查找特定的命名消息。我怀疑它与命名空间有关,几乎所有让我对 XSLT 感到困惑的事情都是如此,但我不明白为什么?
有人可以为我阐明这一点吗?我不喜欢尝试寻找解决方案,因为它不会导致理解。
WSDL 的相关部分是:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="retrieveCustomerYtdResponse">
<part name="parameter"/>
</message>
<message name="retrieveCustomerYtdRequest"/>
</definitions>
I can not find a good explanation for why the second example here works but the first does not:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsd"
version="2.0">
<xsl:template match="/">
<xsl:value-of select="/wsdl:definitions/wsdl:message[@name = $messageName]"/>
<xsl:value-of select="/wsdl:definitions/wsdl:message/@name[. = $messageName]"/>
</xsl:template>
</xsl:stylesheet>
The context is finding a specific named message in a WSDL document. I suspect it has something to do with namespacing just about everything that trips me up badly with XSLT is but I do not understand why?
could someone shine a light on this for me I don't like experimenting to get a solution as it does not lead to understanding.
the relevent sections of the WSDL are:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="retrieveCustomerYtdResponse">
<part name="parameter"/>
</message>
<message name="retrieveCustomerYtdRequest"/>
</definitions>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不存在任何关于命名空间的问题。两个表达式都是正确的并产生预期的结果。
假设(至少)有一个指令的上下文模板,在第一条指令中,您尝试使用给定的 @name 打印 wsdl:message 的文本节点后代。由于该元素内没有文本,因此不会打印任何内容。
第二条指令将打印@name的值。这是正确的。
There is no any issue about namespaces. Both expressions are correct and produce the expected result.
Assuming (at least) a context template for the instructions, with the first instruction you are trying to print the text nodes descendant of wsdl:message with given @name. Nothing will be printed out as no text inside that element.
The second instruction will print the value of @name. That's correct.