2012-02-18 9 views
1

xslでのnamespaceの経験はあまりありません。xmlを変換するためにxslを使用しています。ここに私が試してみましたXSLはXSLが動作していないXML名前空間

、ある
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <xsl:template name="start" match="/"> 
     <xsl:if test="//HotelSearchCriteria/HotelRef/@HotelCityName != ''"> 
      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:b2bHotelSOAP" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
       <soap:Header/> 
       <soap:Body> 
        <urn:getAvailableHotel soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> 
         <apiKey xsi:type="xsd:string"> 
          <xsl:value-of select="//ApiKey"/> 
         </apiKey> 
         <destinationId xsi:type="xsd:string"> 
          <xsl:value-of select="//HotelRef/@HotelCityCode"/> 
         </destinationId> 
         <checkIn xsi:type="xsd:date"> 
          <xsl:value-of select="//StayDateRange/@Start"/> 
         </checkIn> 
         <checkOut xsi:type="xsd:date"> 
          <xsl:value-of select="//StayDateRange/@End"/> 
         </checkOut> 
         <currency xsi:type="xsd:string"> 
          <xsl:value-of select="//Currency"/> 
         </currency> 
         <clientNationality xsi:type="xsd:string"> 
          <xsl:value-of select="//Nationality"/> 
         </clientNationality> 
         <onRequest xsi:type="xsd:boolean"> 
          <xsl:value-of select="//HotelAdvanacedSearchCriteria/Available"/> 
         </onRequest> 
         <rooms xsi:type="urn:roomArray" soapenc:arrayType="urn:paxesArray"> 
          <xsl:apply-templates select="//HotelSearchCriteria/Rooms/Room" mode="search"/> 

         </rooms> 
         <filters xsi:type="urn:filterArray" soapenc:arrayType="urn:filter"/> 
        </urn:getAvailableHotel> 
       </soap:Body> 
      </soap:Envelope> 
     </xsl:if> 
    </xsl:template> 
    <xsl:template match="Room"> 
     <paxes> 
      <xsl:attribute name="xsi:type">urn:paxesArray</xsl:attribute> 

     </paxes> 
    </xsl:template> 

</xsl:stylesheet> 

:ここ

は私が

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:b2bHotelSOAP" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
    <soap:Header/> 
    <soap:Body> 
     <urn:getAvailableHotel soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> 
      <destinationId xsi:type="xsd:string">666</destinationId> 
      <checkIn xsi:type="xsd:date">2011-09-01</checkIn> 
      <checkOut xsi:type="xsd:date">2011-09-03</checkOut> 
      <currency xsi:type="xsd:string">USD</currency> 
      <clientNationality xsi:type="xsd:string">US</clientNationality> 
      <onRequest xsi:type="xsd:boolean">True</onRequest> 
         <rooms xsi:type="urn:roomArray" soapenc:arrayType="urn:paxesArray"> 
      <paxes> 
       <pax> 
        <paxType>Adult</paxType> 
       </pax> 
      </paxes> 
         </rooms> 

     </urn:getAvailableHotel> 
    </soap:Body> 
</soap:Envelope> 

EDIT、などの出力を期待していたXML入力、

<GetAvailability> 
    <RequestSection> 
     <Hotel> 
      <StayDateRange Start="25/02/2012" End="27/02/2012"/> 
      <HotelSearchCriteria> 
       <HotelRef HotelCityName="MUMBAI" HotelCityCode="666" Currency="USD" Nationality="US"/> 
       <Rooms> 
       <Room Type="Single" ChildCount="1" AdultsCount="1" ExtraBed="0" RateBasis="-1"> 
        <Ages> 
         <Age>5</Age> 
        </Ages> 
       </Room> 
      </Rooms> 

      </HotelSearchCriteria> 
     </Hotel> 
    </RequestSection> 
</GetAvailability> 

ですこのクエリの解決策を私に教えてください。

+1

[何を試しましたか?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – nfechner

+0

@nfechner Excellent! – Filburt

+0

xslで編集しました! – Sujit

答えて

1

あなたの実際の問題はRoomテンプレートであるように、あなたのXSL変換、それはxsi名前空間を認識しない文句を言うので...

<xsl:template match="Room"> 
    <paxes> 
     <xsl:attribute name="xsi:type">urn:paxesArray</xsl:attribute> 
    </paxes> 
</xsl:template> 

...そうです。

これを修正するには、使用するすべてのテンプレートに名前空間を追加するか、トップレベルで<xsl:stylesheet />の内側に追加する必要があります。

<xsl:template match="Room" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <paxes> 
     <xsl:attribute name="xsi:type">urn:paxesArray</xsl:attribute> 
    </paxes> 
</xsl:template> 

か - あなたはあなたのstartテンプレート

<xsl:template match="Room" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <paxes xsi:type="urn:paxesArray"> 
     <xsl:apply-templates /> 
    </paxes> 
</xsl:template> 

であなたの属性を追加する方法を維持したいそして、あなたはroomsの内側にあなたのRoomテンプレートを適用する変更する必要がある場合にだけ<apply-templates />

<rooms xsi:type="urn:roomArray" soapenc:arrayType="urn:paxesArray"> 
    <xsl:apply-templates /> 
</rooms> 
+0

あなたのソリューションに感謝、それは正常に動作しています。 – Sujit

関連する問題