XML到SOAP的转换

时间:2011-05-31 03:40:45

标签: xml xslt soap

我是XML,XSLT和SOAP的新手,我想知道是否可以转换这个XML文件

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

<SEARCHREQUEST>

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

</SEARCHREQUEST>

进入此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。如果有可能,你能否指出一些展示如何实现这一目标的例子。 Michael Kay的“XSLT 2.0和XPath 2.0程序员参考文献(第4版)”提供了大量关于如何将XML转换为HTML但没有关于XML转换为SOAP的示例。我能找到的最接近的是

http://wiki.netbeans.org/TransformingSOAPMessagesWithXSLT

显示了如何转换SOAP请求,这不是我需要的。感谢您的帮助。

1 个答案:

答案 0 :(得分: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>