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

Transform SOAP Request with XSLT | For Each Loop Issue

我有一个如下所示的 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 专门针对 "Description" 节点。我想做的是提取每个 "ExtendedOptionItem".

的描述

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

当只有一个 "ExtendedOptionItem" 时,这个 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>

This XSLT works absolutely fine when there is only one "ExtendedOptionItem".

不,不是。

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

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

什么都不选。尝试将其更改为:

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