2016-05-04 71 views
0

我正在使用BPEL流程編排兩個Web服務。基本上,這兩個Web服務返回書對象。 第一web服務返回以下數據格式:使用XSLT更改數據格式

<soapenv:Envelope 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:Body> 
    <searchBooksResponse xmlns="urn:soft.xyz.ac.be/"> 
     <book xmlns=""> 
     <author>Robert Ludlum</author> 
     <year>2004</year> 
     <isbn>95248457</isbn> 
     <language>fr</language> 
     <publisher>Orion</publisher> 
     <title>La Mémoire dans la peau (SOFT Library)</title> 
     </book> 
     <book xmlns=""> 
     <author>Douglas Adams</author> 
     <year>2002</year> 
     <isbn>60184547</isbn> 
     <language>fr</language> 
     <publisher>Del Rey</publisher> 
     <title>Le Guide du Voyageur Galactique (SOFT Library)</title> 
     </book> 

    </searchBooksResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

第二返回以下格式:

<soapenv:Envelope 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:Body> 
    <searchForBooksResponse xmlns="http://library.be"> 
     <searchForBooksReturn> 
     <author>James, E. L.</author> 
     <date>3914-01-10T23:00:00.000Z</date> 
     <isbn>0345803485</isbn> 
     <language>English</language> 
     <publisher>Vintage Books</publisher> 
     <title>50 Shades of Grey (National Library)</title> 
     </searchForBooksReturn> 
     <searchForBooksReturn> 
     <author>James Dashner</author> 
     <date>3914-04-20T22:00:00.000Z</date> 
     <isbn>0385388896</isbn> 
     <language>English</language> 
     <publisher>The Maze Runner Series</publisher> 
     <title>The Maze Runner Series (National Library)</title> 
     </searchForBooksReturn> 
    </searchForBooksResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

要合併的結果,我用下面的BPEL命令xls文件。下面是BPEL命令:

<![CDATA[bpel:doXslTransform("books.xsl", $sl_searchBooksResponse.parameters, "second", $nl_searchForBooksResponse.parameters/*)]]> 

,這裏是XSL文件:

<?xml version="1.0" encoding="UTF-8"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL 

/Transform" xmlns="urn:soft.librarysearch" xmlns:tns="urn:soft.librarysearch" xmlns:nl="http://library.be"> 
     <xsl:param name="second"> 
     foo 
     </xsl:param> 
     <xsl:template match="/"> 
      <root> 
       <xsl:apply-templates /> 
       <xsl:copy-of select="$second"/> 
      </root> 
     </xsl:template> 

     <xsl:template match="@*|node()"> 
      <xsl:copy> 
       <xsl:apply-templates/> 
      </xsl:copy> 
     </xsl:template> 
     </xsl:template> --> 

    </xsl:stylesheet> 

但是,結果顯示不一致如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> 
    <LibrarySearchResponse xmlns="urn:soft.librarysearch" xmlns:tns="urn:soft.librarysearch"> 
          <tns:query/> 
          <tns:books xmlns:nl="http://library.be"> 
     <searchBooksResponse xmlns="urn:soft.xxx.ac.be/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
      <book xmlns=""> 
      <author>Robert Ludlum</author> 
      <year>2004</year> 
      <isbn>95248457</isbn> 
      <language>fr</language> 
      <publisher>Orion</publisher> 
      <title>La Mémoire dans la peau (SOFT Library)</title> 
      </book> 
      <book xmlns=""> 
      <author>Douglas Adams</author> 
      <year>2002</year> 
      <isbn>60184547</isbn> 
      <language>fr</language> 
      <publisher>Del Rey</publisher> 
      <title>Le Guide du Voyageur Galactique (SOFT Library)</title> 
      </book> 
     </searchBooksResponse> 


     <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
      <author>James, E. L.</author> 
      <date>3914-01-10T23:00:00.000Z</date> 
      <isbn>0345803485</isbn> 
      <language>English</language> 
      <publisher>Vintage Books</publisher> 
      <title>50 Shades of Grey (National Library)</title> 
     </searchForBooksReturn> 
     <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
      <author>James Dashner</author> 
      <date>3914-04-20T22:00:00.000Z</date> 
      <isbn>0385388896</isbn> 
      <language>English</language> 
      <publisher>The Maze Runner Series</publisher> 
      <title>The Maze Runner Series (National Library)</title> 
     </searchForBooksReturn> 
     </tns:books> 
         </LibrarySearchResponse> </soapenv:Body> </soapenv:Envelope> 

我想用所有的書對象相同的標籤「」,他們應該被放置在相同的水平通過刪除標籤「searchBooksResponse「。例如,將標籤「searchForBooksReturn」更改爲「book」。我怎樣才能做到這一點?感謝您的耐心解答我長期以來的問題。

回答

1

關於如何:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:nl="http://library.be" 
exclude-result-prefixes="nl"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:param name="second"/> 

<xsl:template match="/"> 
    <root> 
     <xsl:apply-templates select="//book"/> 
     <xsl:apply-templates select="$second//nl:searchForBooksReturn"/> 
    </root> 
</xsl:template> 

<xsl:template match="nl:searchForBooksReturn"> 
    <book> 
     <xsl:apply-templates/> 
    </book> 
</xsl:template> 

<xsl:template match="*"> 
    <xsl:element name="{local-name()}"> 
     <xsl:apply-templates/> 
    </xsl:element> 
</xsl:template> 

</xsl:stylesheet> 
+0

謝謝你,但它只是從兩個Web服務(國家圖書館)一個返回的數據。下面是返回的數據的格式: ... ... lenhhoxung

+0

@lenhhoxung我不明白你的意見。我使用你在問題中發佈的「返回數據格式*」來測試它(除了我使用文件而不是「第二個」響應)。 –

+0

@ michael.hork257k:我的意思是如果我使用我的xls文件,我將從包括SOFT LIBRARY和NATIONAL LIBRARY在內的兩個Web服務返回數據。如果我使用你的xls文件,我只收到NATIONAL LIBRARY的數據。來自NATIONAL LIBRARY的數據總是被標籤所包圍 lenhhoxung