soapEnvolpe 및 네임 스페이스없이 xml을 하나로 변환하고 xslt를 사용하여 내부 요소에 네임 스페이스 추가

수 라즈 무랄 레이다 란

나는 soapEnvolope 및 soapBody없이 xml을 새 XML로 변환하는 작업을 해왔습니다. 또한 기존의 여러 네임 스페이스를 삭제하고 단일 (및 새로운) 네임 스페이스로 교체하려고합니다.

아래에서 변환하려는 xml을 찾으십시오.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns11:IATA_InvGuaranteeRS xmlns:ns2="http://www.iata.org/IATA/2015/00/2019.2/IATA_InvGuaranteeRS" xmlns:ns3="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderChangeRQ" xmlns:ns4="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderViewRS" xmlns:ns5="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderRetrieveRQ" xmlns:ns6="http://www.iata.org/IATA/2015/00/2019.2/IATA_InvReleaseNotifRQ" xmlns:ns7="http://www.iata.org/IATA/2015/00/2019.2/IATA_Acknowledgement" xmlns:ns8="http://www.iata.org/IATA/2015/00/2019.2/IATA_OfferPriceRQ" xmlns:ns9="http://www.iata.org/IATA/2015/00/2019.2/IATA_OfferPriceRS" xmlns:ns10="http://www.iata.org/IATA/2015/00/2019.2/IATA_AirShoppingRQ" xmlns:ns11="http://www.iata.org/IATA/2015/00/2019.2/IATA_AirShoppingRS" xmlns:ns12="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderCreateRQ" xmlns:ns13="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderReshopRQ" xmlns:ns14="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderReshopRS" xmlns:ns15="http://www.iata.org/IATA/2015/00/2019.2/IATA_SeatAvailabilityRQ" xmlns:ns16="http://www.iata.org/IATA/2015/00/2019.2/IATA_SeatAvailabilityRS" xmlns:ns17="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderCancelRQ" xmlns:ns18="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderCancelRS" xmlns:ns19="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderRulesRQ" xmlns:ns20="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderRulesRS" xmlns:ns21="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderListRQ" xmlns:ns22="http://www.iata.org/IATA/2015/00/2019.2/IATA_OrderListRS" xmlns:ns23="http://www.iata.org/IATA/2015/00/2019.2/IATA_ServiceListRQ" xmlns:ns24="http://www.iata.org/IATA/2015/00/2019.2/IATA_ServiceListRS" xmlns:ns25="http://www.iata.org/IATA/2015/00/2019.2/IATA_InvGuaranteeRQ" xmlns:ns26="http://www.travel.com/wsdl/ndc">
            <ns11:Response>
                <ns11:DataLists>
                    <ns11:OriginDestList>
                        <ns11:OriginDest>
                            <ns11:DestCode>AYT</ns11:DestCode>
                            <ns11:Origin Code="FRA">FRA</ns11:Origin>
                            <ns11:OriginDestID>V1_OD.1595044928630</ns11:OriginDestID>
                            <ns11:PaxJourneyRefID>V1_FL.1595044929364</ns11:PaxJourneyRefID>
                        </ns11:OriginDest>
                    </ns11:OriginDestList>
                </ns11:DataLists>
            </ns11:Response>
        </ns11:IATA_InvGuaranteeRS>
    </soap:Body>
</soap:Envelope>

내가 생각 해낸 xslt를 찾으십시오. 그러나 불완전합니다. 내가 놓친 것이 무엇인지 알고 싶습니다. xslt 1.0 솔루션을 구현하려고합니다.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:iata="http://www.iata.org/IATA/2015/00/2019.2/IATA_InvGuaranteeRS"
                xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" version="2.0">
    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <!-- remove all elements in the soapenv namespace -->
    <xsl:template match="soapenv:*">
        <xsl:apply-templates select="node()"/>
    </xsl:template>
    <xsl:template match="*">
        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="@* | node()" />
        </xsl:element>
    </xsl:template>
    <xsl:template match="@*">
        <xsl:attribute name="{local-name()}">
            <xsl:value-of select="." />
        </xsl:attribute>
    </xsl:template>
    <xsl:template match="text() | comment() | processing-instruction()">
        <xsl:copy />
    </xsl:template>
</xsl:stylesheet>

예상되는 결과는

<IATA_InvGuaranteeRS xmlns:iata="http://www.iata.org/IATA/2015/00/2019.2/IATA_InvGuaranteeRS">
    <Response>
        <DataLists>
            <OriginDestList>
                <OriginDest>
                    <DestCode>AYT</DestCode>
                    <Origin Code="FRA">FRA</Origin>
                    <OriginDestID>V1_OD.1595044928630</OriginDestID>
                    <PaxJourneyRefID>V1_FL.1595044929364</PaxJourneyRefID>
                </OriginDest>
            </OriginDestList>
        </DataLists>
    </Response>
</IATA_InvGuaranteeRS>

누군가 내가 놓친 것을 이해하도록 도울 수 있습니까? 내가 생성 한 xslt는 모든 네임 스페이스를 제거하고 그 뒤에 네임 스페이스를 추가 할 수 없습니다.

완전한

루트 노드의 기본 네임 스페이스의 namespace경우 *템플릿에 인수를 추가하기 만하면됩니다 .

<xsl:template match="*">
    <xsl:element name="{local-name()}" namespace="http://www.iata.org/IATA/2015/00/2019.2/IATA_InvGuaranteeRS">
        <xsl:apply-templates select="@* | node()" />
    </xsl:element>
</xsl:template>

Online Demo

iata루트 노드 와 같이 접두사가 붙은 네임 스페이스의 경우 새 템플릿을 추가하여 루트를 다시 작성합니다.

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

    ...same as before...

    <xsl:template match="ns11:IATA_InvGuaranteeRS">
        <IATA_InvGuaranteeRS xmlns:iata="http://www.iata.org/IATA/2015/00/2019.2/IATA_InvGuaranteeRS">
            <xsl:apply-templates select="@* | node()" />
        </IATA_InvGuaranteeRS>
    </xsl:template>
</xsl:stylesheet>

Online Demo

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관