【问题标题】:XSLT Attribute Matching With NamespacesXSLT 属性与命名空间匹配
【发布时间】:2011-11-08 21:03:52
【问题描述】:

我无法很好地解释为什么这里的第二个示例有效但第一个无效:

<?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>

【问题讨论】:

    标签: xslt attributes namespaces matching


    【解决方案1】:

    关于命名空间没有任何问题。这两个表达式都是正确的,并且产生了预期的结果。

    假设(至少)指令的上下文模板,您尝试使用给定 @name 打印 wsdl:message 的文本节点后代的第一条指令.由于该元素内没有文本,因此不会打印任何内容。

    第二条指令将打印 @name 的值。没错。

    【讨论】:

    • 是的,您完全正确,感谢您的解释。第一个表达式确实返回了文本节点,这就是我所缺少的知识。如果我现在理解正确 /wsdl:definitions/wsdl:message[@name = $messageName]/@name 在这种情况下会给我我想要的。
    • 是的。这是正确的。如果您认为您的问题已解决,请务必发送至 accept the answer
    • 就个人而言,我更喜欢 XPath 表达式,其中 @name 只重复一次。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 2018-11-18
    • 2010-10-27
    相关资源
    最近更新 更多