0

I am new to XML, XSLT and SOAP and I would like to know whether it's possible to transform this XML file

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

<SEARCHREQUEST>

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

</SEARCHREQUEST>

into this SOAP request

<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>

using XSLT only. If it's possible, could you point me to some examples that show how to accomplish this. "XSLT 2.0 and XPath 2.0 Programmer's Reference (4th ed.)" by Michael Kay has plenty of examples of how to transform XML to HTML but nothing on XML to SOAP transformations. The closest thing I could find is here

http://wiki.netbeans.org/TransformingSOAPMessagesWithXSLT

which shows how to transform SOAP requests, which isn't what I need. Thank you for your help in advance.

Sergey Koulikov
  • 267
  • 4
  • 7
  • 16
  • I think it should be very easy, just need to declare the correct namespace in the transform. Are you searching just for a transform which generates the SOP request as you presented, then just getting some value from the input PSSSEARCHPARAM? – Emiliano Poggi May 31 '11 at 03:49
  • That's exactly what I am trying to do. – Sergey Koulikov May 31 '11 at 03:57
  • In my answer I show you how to get the values from you search request and put it into the various `ProfileSearchParameter`. – Emiliano Poggi May 31 '11 at 04:30

1 Answers1

2

So, or your question is really simple, or I'm missing something obvious...Are you searching for something like this?

<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>
Emiliano Poggi
  • 24,390
  • 8
  • 55
  • 67
  • Thank you. It seemed that my question was too simple. – Sergey Koulikov May 31 '11 at 05:52
  • I am using Mule ESB and right after a service call, I am getting back a SOAP response in SOAPUI, but surprisingly, it is without the SOAP envelope and body tags! The tomcat console (my services are running on a local test server) however gives the complete SOAP payload in the correct format. I will try and use this method to add those envelope and body tags. – Chinmoy Apr 25 '12 at 06:12