簡體   English   中英

使用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專門針對“描述”節點。 我想做的是為每個“ 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>

當只有一個“ ExtendedOptionItem”時,此XSLT絕對可以正常工作。

不,不是。

問題是您的模板與/根節點匹配-而ExtendedOptionItem不是/根節點的子級。 結果,您:

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

什么都不選擇。 嘗試將其更改為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM