使用 XSLT 转换 SOAP 请求 |对于每个循环问题



我有一个 SOAP 请求,如下所示;

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetCountriesResponse xmlns="url">
      <GetCountriesResult>
        <ExtendedOptionItem>
          <Value>GB</Value>
          <Description>United Kingdom</Description>
          <Active>true</Active>
          <IsDefault>true</IsDefault>
          <Order>0</Order>
        </ExtendedOptionItem>
        <ExtendedOptionItem>
          <Value>GB</Value>
          <Description>United Kingdom</Description>
          <Active>true</Active>
          <IsDefault>true</IsDefault>
          <Order>0</Order>
        </ExtendedOptionItem>
      </GetCountriesResult>
    </GetCountriesResponse>
  </soap:Body>
</soap:Envelope>

我的 XSLT 目前专门针对"描述"节点。我想做的是提取每个"扩展选项项"的描述。

我已经编写了一些 XSLT,需要用分号分隔每个描述。

当只有一个"扩展选项项"时,此XSLT绝对可以正常工作。但是,当有多个项目时,不会转换 XML。

请您查看我的 XSLT 并评估我出错的地方;

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="yes" />
<xsl:template match="/">
  <xsl:for-each xmlns:n="url" select="n:ExtendedOptionItem">
<xsl:value-of select="n:Description" />;</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

非常感谢

更新;

SOAP 响应由工作流引擎修改,如下所示;

<ExtendedOptionItem xmlns="url"><Value>GB</Value><Description>United Kingdom</Description><Active>true</Active><IsDefault>true</IsDefault><Order>0</Order></ExtendedOptionItem><ExtendedOptionItem xmlns="url"><Value>AF</Value><Description>Afghanistan</Description><Active>true</Active><IsDefault>false</IsDefault><Order>0</Order></ExtendedOptionItem><ExtendedOptionItem xmlns="url"><Value>AX</Value><Description>Åland Islands</Description><Active>true</Active><IsDefault>false</IsDefault><Order>0</Order></ExtendedOptionItem>

当只有一个时,此 XSLT 工作绝对正常 "扩展选项项"。

不,它没有。

问题是您的模板与/根节点匹配 - 并且ExtendedOptionItem不是/根节点的子节点。因此,您的:

<xsl:for-each xmlns:n="url" select="n:ExtendedOptionItem">

不选择任何内容。尝试将其更改为:

<xsl:for-each xmlns:n="url" select="//n:ExtendedOptionItem">

最新更新