Преобразовать XML Soap с помощью xslt - PullRequest
0 голосов
/ 02 августа 2020

У меня есть запрос soap, и мне нужно его преобразовать.

soap xml:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns:getReservationsResponse xmlns:ns="http://webService/xsd">
         <ns:return>
            <resid xmlns="http://reservation.proxsafe.deister.de/xsd">100</resid>
            <active xmlns="http://reservation.proxsafe.deister.de/xsd">true</active>
         </ns:return>
      </ns:getReservationsResponse>
        </soapenv:Body>
    </soapenv:Envelope>

Сначала я использую xsl, чтобы удалить все soap

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
exclude-result-prefixes="soapenv">

<xsl:strip-space elements="*"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<!-- remove all elements in the soapenv namespace -->
<xsl:template match="soapenv:*">
    <xsl:apply-templates select="node()"/>
</xsl:template>

<!-- for the remaining elements (i.e. elements in the default namespace) ... -->
<xsl:template match="*">
    <!-- ... create a new element with similar name in no-namespace -->
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>
</xsl:stylesheet>

Но теперь мне нужно переименовать getReservationsResponse в Data и вернуться к Object Кто может мне помочь?

Ответы [ 2 ]

0 голосов
/ 02 августа 2020

для этого вы можете добавить несколько шаблонов в свой xslt.

в обновлении объявления пространства имен

**xmlns:ns="http://webService/xsd"
xmlns:ns1="http://reservation.proxsafe.deister.de/xsd"**
exclude-result-prefixes="soapenv **ns ns1**"

и добавить шаблоны

<xsl:template match="ns:getReservationsResponse">
    <Data>
        <xsl:apply-templates/>
    </Data>
</xsl:template>


<xsl:template match="ns:return">
    <Object>
        <xsl:apply-templates/>
    </Object>
</xsl:template>

<xsl:template match="ns1:resid">
    <Property Name="ExternalId" Value="{.}" />
</xsl:template>

<xsl:template match="ns1:active">
    <Property Name="Activated" Value="{.}" />
</xsl:template>

test ссылка здесь.

0 голосов
/ 02 августа 2020

Попробуйте так:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://webService/xsd"
exclude-result-prefixes="soapenv ns">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- remove all elements in the soapenv namespace -->
<xsl:template match="soapenv:*">
    <xsl:apply-templates/>
</xsl:template>

<!-- for the remaining elements (i.e. elements in the default namespace) ... -->
<xsl:template match="*">
    <!-- ... create a new element with similar name in no-namespace -->
    <xsl:element name="{local-name()}">
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

<xsl:template match="ns:getReservationsResponse">
    <Data>
        <xsl:apply-templates/>
    </Data>
</xsl:template>

<xsl:template match="ns:return">
    <Object>
        <xsl:apply-templates/>
    </Object>
</xsl:template>

</xsl:stylesheet>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...