【问题标题】:XSLT to get the attribute value from a SOAP RequestXSLT 从 SOAP 请求中获取属性值
【发布时间】:2015-02-25 06:15:51
【问题描述】:

我有以下 SOAP 请求,我需要在 XSLT 模板中提取 IP 地址参数值。

SOAP 请求:

<soapenv:Envelope
xmlns:ws="http://diamondip.com/ipcontrol/ws/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<soapenv:Header />
<soapenv:Body>
<ws:deleteDevice soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<inpDev xsi:type="ser:WSDevice"
xmlns:ser="http://service.ipcontrol.diamondip.com"
>
<ipAddress xsi:type="soapenc:string"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
>xxx.xxx.xx.xx</ipAddress>
</inpDev>
</ws:deleteDevice>
</soapenv:Body>
</soapenv:Envelope>

我尝试使用以下方法获取值,但没有成功

<xsl:variable name="ipAddress" select="soapenv:Envelope/soapenv:Body/ws:deleteDevice/inpDev/ipAddress/text()"/>

感谢任何建议!

【问题讨论】:

  • 请显示您的所有 XSLT 代码并解释 究竟是什么 不起作用。

标签: xslt soap ibm-datapower


【解决方案1】:

我们从您的问题中不知道的一件事是,当您执行 xsl:variable 时,当前上下文节点是什么。如果您当前的上下文节点是根节点,它应该可以工作。

尝试将 XPath 更改为绝对路径(在开头放置一个正斜杠)。如果这不起作用,请确保在 XSLT 中正确定义了所有命名空间。

【讨论】:

    【解决方案2】:

    您可以使用以下代码导航并获取输出。

    <xsl:stylesheet version ="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match ='/'>
    <xsl:variable name="ipAddress" select="/*[local-name() = 'Envelope']/*[local-name() = 'Body']/*[local-name() = 'deleteDevice']/*[local-name() = 'inpDev']/*[local-name() = 'ipAddress']/text()"/>
    IP Adress: <xsl:value-of select = "$ipAddress"/>
    </xsl:template>
    </xsl:stylesheet>
    

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 1970-01-01
      • 2018-09-17
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多