2011-05-31 112 views
0

我新的XML,XSLT和SOAP,我想知道是否有可能這個XML文件XML到SOAP轉型

<?xml version="1.0" encoding="UTF-8"?> 

<SEARCHREQUEST> 

    <PSSSEARCHPARAM1>Database name</PSSSEARCHPARAM1> 
    <PSSSEARCHPARAM2>Description</PSSSEARCHPARAM2> 
    <PSSSEARCHPARAM3>Document number</PSSSEARCHPARAM3> 
    <PSSSEARCHPARAM4>Belong To</PSSSEARCHPARAM4> 

</SEARCHREQUEST> 

轉換成使用XSLT這個SOAP請求

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> 
<soap:Header/> 
<soap:Body> 

    <wor:SearchDocuments xmlns:wor="http://worksite.imanage.com"> 

     <wor:Databases> 
      <wor:string>Database name</wor:string> 
     </wor:Databases> 

     <wor:ProfileSearchParameters> 

      <wor:ProfileSearchParameter>  
       <wor:AttributeID>imProfileDescription</wor:AttributeID> 
       <wor:SearchValue>Description</wor:SearchValue> 
      </wor:ProfileSearchParameter> 

      <wor:ProfileSearchParameter> 
       <wor:AttributeID>imProfileCustom3</wor:AttributeID> 
       <wor:SearchValue>Belong To</wor:SearchValue> 
      </wor:ProfileSearchParameter> 

      <wor:ProfileSearchParameter> 
       <wor:AttributeID>imProfileCustom4</wor:AttributeID> 
       <wor:SearchValue>APP, 20</wor:SearchValue> 
      </wor:ProfileSearchParameter> 

      <wor:ProfileSearchParameter> 
       <wor:AttributeID>imProfileDocNum</wor:AttributeID> 
       <wor:SearchValue>Document number</wor:SearchValue> 
      </wor:ProfileSearchParameter> 

     </wor:ProfileSearchParameters> 

     <wor:SearchEmail>imSearchDocumentsOnly</wor:SearchEmail> 

     <wor:OutputMask>Profile</wor:OutputMask> 

     <wor:OutputProfile> 

      <!-- Displays the document number--> 
      <wor:imProfileAttributeID>imProfileDocNum</wor:imProfileAttributeID> 

      <!-- Displays the document description/title--> 
      <wor:imProfileAttributeID>imProfileDescription</wor:imProfileAttributeID> 

      <!--Displays the document version--> 
      <wor:imProfileAttributeID>imProfileVersion</wor:imProfileAttributeID> 

      <!--Displays the standard id--> 
      <wor:imProfileAttributeID>imProfileCustom16</wor:imProfileAttributeID> 

      <!--Display the "Belong to" field--> 
      <wor:imProfileAttributeID>imProfileCustom3</wor:imProfileAttributeID> 

      <!--Displays the database name--> 
      <wor:imProfileAttributeID>imProfileDatabase</wor:imProfileAttributeID> 

      <!--Displays the document extension--> 
      <wor:imProfileAttributeID>imProfileExtension</wor:imProfileAttributeID> 

     </wor:OutputProfile> 
    </wor:SearchDocuments> 
</soap:Body> 
</soap:Envelope> 

只要。如果可能的話,你能否指出一些例子來說明如何實現這一點。邁克爾凱的「XSLT 2.0和XPath 2.0程序員參考(第4版)」有很多關於如何將XML轉換爲HTML的示例,但沒有將XML轉換爲SOAP轉換。我能找到最接近的是這裏

http://wiki.netbeans.org/TransformingSOAPMessagesWithXSLT

它展示瞭如何轉換SOAP請求,這不是我所需要的。提前謝謝你的幫助。

+0

我覺得應該很簡單,只需要在變換中聲明正確的名稱空間即可。您是否正在尋找一種轉換來生成SOP請求,然後從輸入PSSSEARCHPARAM中獲取一些值? – 2011-05-31 03:49:44

+0

這正是我想要做的。 – 2011-05-31 03:57:11

+0

在我的回答中,我向您展示瞭如何從您的搜索請求中獲取值,並將其放入各種'ProfileSearchParameter'中。 – 2011-05-31 04:30:51

回答

2

所以,或者你的問題很簡單,或者我錯過了一些明顯的東西......你在尋找這樣的東西嗎?

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" indent="yes"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="/SEARCHREQUEST"> 
     <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> 
      <soap:Header/> 
      <soap:Body> 

       <wor:SearchDocuments xmlns:wor="http://worksite.imanage.com"> 

        <wor:Databases> 
         <wor:string><xsl:value-of select="PSSSEARCHPARAM1"/></wor:string> 
        </wor:Databases> 

        <wor:ProfileSearchParameters> 

         <wor:ProfileSearchParameter>  
          <wor:AttributeID>imProfileDescription</wor:AttributeID> 
          <wor:SearchValue><xsl:value-of select="PSSSEARCHPARAM2"/></wor:SearchValue> 
         </wor:ProfileSearchParameter> 

         <wor:ProfileSearchParameter> 
          <wor:AttributeID>imProfileCustom3</wor:AttributeID> 
          <wor:SearchValue><xsl:value-of select="PSSSEARCHPARAM4"/></wor:SearchValue> 
         </wor:ProfileSearchParameter> 

         <wor:ProfileSearchParameter> 
          <wor:AttributeID>imProfileCustom4</wor:AttributeID> 
          <wor:SearchValue>APP, 20</wor:SearchValue> 
         </wor:ProfileSearchParameter> 

         <wor:ProfileSearchParameter> 
          <wor:AttributeID>imProfileDocNum</wor:AttributeID> 
          <wor:SearchValue><xsl:value-of select="PSSSEARCHPARAM3"/></wor:SearchValue> 
         </wor:ProfileSearchParameter> 

        </wor:ProfileSearchParameters> 

        <wor:SearchEmail>imSearchDocumentsOnly</wor:SearchEmail> 

        <wor:OutputMask>Profile</wor:OutputMask> 

        <wor:OutputProfile> 

         <!-- Displays the document number--> 
         <wor:imProfileAttributeID>imProfileDocNum</wor:imProfileAttributeID> 

         <!-- Displays the document description/title--> 
         <wor:imProfileAttributeID>imProfileDescription</wor:imProfileAttributeID> 

         <!--Displays the document version--> 
         <wor:imProfileAttributeID>imProfileVersion</wor:imProfileAttributeID> 

         <!--Displays the standard id--> 
         <wor:imProfileAttributeID>imProfileCustom16</wor:imProfileAttributeID> 

         <!--Display the "Belong to" field--> 
         <wor:imProfileAttributeID>imProfileCustom3</wor:imProfileAttributeID> 

         <!--Displays the database name--> 
         <wor:imProfileAttributeID>imProfileDatabase</wor:imProfileAttributeID> 

         <!--Displays the document extension--> 
         <wor:imProfileAttributeID>imProfileExtension</wor:imProfileAttributeID> 

        </wor:OutputProfile> 
       </wor:SearchDocuments> 
      </soap:Body> 
     </soap:Envelope>   
    </xsl:template> 

</xsl:stylesheet> 
+0

謝謝。似乎我的問題太簡單了。 – 2011-05-31 05:52:04

+0

我正在使用Mule ESB,並且在服務調用之後,我在SOAPUI中取回SOAP響應,但令人驚訝的是,它沒有SOAP信封和主體標籤! tomcat控制檯(我的服務在本地測試服務器上運行)然而以正確的格式提供完整的SOAP有效負載。我會嘗試使用這種方法來添加這些信封和身體標籤。 – r3st0r3 2012-04-25 06:12:23