#xml #xslt #soap
#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. Если это возможно, не могли бы вы указать мне на несколько примеров, которые показывают, как этого добиться. «Справочник программиста XSLT 2.0 и XPath 2.0 (4-е изд.)» Майкла Кея содержит множество примеров того, как преобразовать XML в HTML, но ничего о преобразованиях XML в SOAP. Самое близкое, что я смог найти, находится здесь
http://wiki.netbeans.org/TransformingSOAPMessagesWithXSLT
в котором показано, как преобразовывать запросы SOAP, что мне не нужно. Заранее благодарю вас за помощь.
Комментарии:
1. Я думаю, это должно быть очень просто, просто нужно объявить правильное пространство имен в преобразовании. Вы ищете просто преобразование, которое генерирует запрос SOP, как вы представили, а затем просто получаете некоторое значение из входного параметра PSSSEARCHPARAM?
2. Это именно то, что я пытаюсь сделать.
3. В моем ответе я покажу вам, как получить значения из вашего поискового запроса и поместить их в различные
ProfileSearchParameter
.
Ответ №1:
Итак, или ваш вопрос действительно прост, или я упускаю что-то очевидное…Вы ищете что-то подобное?
<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>
Комментарии:
1. Спасибо. Казалось, что мой вопрос был слишком простым.
2. Я использую Mule ESB и сразу после вызова службы получаю ответ SOAP в SOAPUI, но, что удивительно, он без тегов SOAP envelope и body! Консоль tomcat (мои службы запущены на локальном тестовом сервере), однако, предоставляет полную полезную нагрузку SOAP в правильном формате. Я попытаюсь использовать этот метод для добавления этих тегов envelope и body.