I have this basic transformation script:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ibn="http://ibn.traveltainment.de/2009/001" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:ota="http://www.opentravel.org/OTA/2003/05" xmlns:ota1="http://www.opentravel.org/OTA/2002/11" exclude-result-prefixes="SOAP-ENV ota">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:variable name="outermostElementName" select="name(/SOAP-ENV:Envelope/SOAP-ENV:Body/ota:*)"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="count(SOAP-ENV:Envelope/SOAP-ENV:Body) > 0">
<xsl:value-of select="$outermostElementName"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/*"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
in which I'm trying to extract a particular element (root), given a different types of xml inputs.
XML 1: I want to extract "ota:OTA_TT_PkgQuoteRS"
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m2="http://www.opentravel.org/OTA/2002/11" xmlns:m="http://www.opentravel.org/OTA/2003/05" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<m:Security xmlns:m="http://schemas.xmlsoap.org/ws/2002/12/secext">
<m:BinarySecurityToken>88096378-085d-102d-8733-001ec9ebbbf0</m:BinarySecurityToken>
</m:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ota:OTA_TT_PkgQuoteRS xmlns:ota="http://www.opentravel.org/OTA/2003/05" Version="1.0" TransactionIdentifier="623">
<ota:Success/>
<ota:Package BrandCode="NLOA" Status="Available" ProductCode="OASVHE1201">
<DateRange xmlns="http://www.opentravel.org/OTA/2003/05" End="2009-11-02" Start="2009-10-30"/>
<ota:ItineraryItems>
<ota:ItineraryItem RPH="1" Status="Available">
<ota:Flight ArrivalDateTime="2009-10-30T13:10:00" DepartureDateTime="2009-10-30T09:40:00" DirectionInd="Outbound" Type="Scheduled">
<ota:DepartureAirport LocationCode="AMS"/>
<ota:ArrivalAirport LocationCode="HEL"/>
<ota:OperatingAirline Code="KL" FlightNumber="1167"/>
<ota:CabinAvailability>
<ota:Seat Code="N" Quantity="2"/>
<ota:PassengerRPHs ListOfPassengerRPH="1 2 "/>
</ota:CabinAvailability>
</ota:Flight>
</ota:ItineraryItem>
<ota:ItineraryItem RPH="2" Status="Available">
<ota:Flight ArrivalDateTime="2009-11-02T08:15:00" DepartureDateTime="2009-11-02T06:30:00" DirectionInd="Inbound" Type="Scheduled">
<ota:DepartureAirport LocationCode="HEL"/>
<ota:ArrivalAirport LocationCode="AMS"/>
<ota:OperatingAirline Code="KL" FlightNumber="1164"/>
<ota:CabinAvailability>
<ota:Seat Code="N" Quantity="2"/>
<ota:PassengerRPHs ListOfPassengerRPH="1 2 "/>
</ota:CabinAvailability>
</ota:Flight>
</ota:ItineraryItem>
<ota:ItineraryItem RPH="3" Status="Available">
<ota:Accommodation>
<ota:Identity HotelName="Sokos Helsinki"/>
<ota:DateRange Start="2009-10-30" End="2009-11-02" Duration="P3N"/>
<RoomProfiles xmlns="http://www.opentravel.org/OTA/2003/05">
<RoomProfile BookingCode="OASVHE1201" RPH="1" RoomTypeCode="26300">
<PassengerRPHs ListOfPassengerRPH="1 2 "/>
</RoomProfile>
</RoomProfiles>
<MealPlans xmlns="http://www.opentravel.org/OTA/2003/05">
<MealPlan Code="LO" ListOfRoomRPH="1">
<PassengerRPHs ListOfPassengerRPH="1 2 "/>
</MealPlan>
</MealPlans>
</ota:Accommodation>
</ota:ItineraryItem>
</ota:ItineraryItems>
<ota:CostSummary>
<ota:CostingItems>
<ota:CostingItem PassengerRPH="1" CostBasis="7" Description="Reissom Givenname Surname" Quantity="1">
<ota:UnitCost CurrencyCode="EUR" Amount="294.00"/>
</ota:CostingItem>
<ota:CostingItem PassengerRPH="2" CostBasis="7" Description="Reissom Givenname Surname" Quantity="1">
<ota:UnitCost CurrencyCode="EUR" Amount="294.00"/>
</ota:CostingItem>
<ota:CostingItem CostBasis="26" Description="2x toeslag n-klasse (2 x 24.00)" Quantity="1">
<ota:UnitCost CurrencyCode="EUR" Amount="48.00"/>
</ota:CostingItem>
<ota:CostingItem CostBasis="26" Description="2x brandstof/veilig.toeslag kl /hel (2 x 60.00)" Quantity="1">
<ota:UnitCost CurrencyCode="EUR" Amount="120.00"/>
</ota:CostingItem>
<ota:CostingItem CostBasis="26" Description="2x luchthavenbelasting kl /hel (2 x 45.00)" Quantity="1">
<ota:UnitCost CurrencyCode="EUR" Amount="90.00"/>
</ota:CostingItem>
<ota:CostingItem CostBasis="26" Description="Calamiteitenfonds" Quantity="1">
<ota:UnitCost CurrencyCode="EUR" Amount="2.50"/>
</ota:CostingItem>
</ota:CostingItems>
<ota:GrossAmount Amount="848.50" CurrencyCode="EUR"/>
</ota:CostSummary>
</ota:Package>
<PassengerListItems xmlns="http://www.opentravel.org/OTA/2003/05">
<PassengerListItem BirthDate="1984-10-01" Code="10" RPH="1">
<Name>
<GivenName>GivenName</GivenName>
<Surname>Surname</Surname>
</Name>
</PassengerListItem>
<PassengerListItem BirthDate="1984-10-01" Code="10" RPH="2">
<Name>
<GivenName>GivenName</GivenName>
<Surname>Surname</Surname>
</Name>
</PassengerListItem>
</PassengerListItems>
</ota:OTA_TT_PkgQuoteRS>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML 2: I want to extract "OTA_TT_PkgBookRS"
<?xml version="1.0" encoding="UTF-8"?>
<OTA_TT_PkgBookRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.1" TimeStamp="2009-10-12T13:01:37+02:00" Target="Test" TransactionIdentifier="27133389004865250">
<Success/>
<Warnings>
<Warning Type="3" ShortText="0014"/>
</Warnings>
<PackageReservation CreateDateTime="2009-10-07T00:00:00" LastModifierID="EUGEN" PurgeDate="2009-10-14" CreatorID="EUGEN">
<UniqueID Type="23" ID="13047087" Instance="1"/>
<Package Status="ToConfirm" BrandCode="JETN" TravelCode="NEFB">
<DateRange Start="2010-01-03" Duration="P7D" End="2010-01-10"/>
<ItineraryItems>
<ItineraryItem RPH="1" Status="Available">
<Flight RPH="1" TravelCode="09" Type="Charter" DirectionInd="Outbound" DepartureDateTime="2010-01-03T00:00:00" ArrivalDateTime="2010-01-03T00:00:00">
<DepartureAirport LocationCode="PAR"/>
<ArrivalAirport LocationCode="DJE"/>
<OperatingAirline Code="TO" FlightNumber="111"/>
<CabinAvailability>
<Seat Code="0" CodeContext="2"/>
<PassengerRPHs ListOfPassengerRPH="1 2"/>
</CabinAvailability>
<FlightSegments/>
</Flight>
</ItineraryItem>
<ItineraryItem RPH="2" Status="Available">
<Flight RPH="1" TravelCode="09" Type="Charter" DirectionInd="Inbound" DepartureDateTime="2010-01-10T00:05:00" ArrivalDateTime="2010-01-10T00:10:00">
<DepartureAirport LocationCode="DJE"/>
<ArrivalAirport LocationCode="PAR"/>
<OperatingAirline Code="TO" FlightNumber="222"/>
<CabinAvailability>
<Seat Code="0" CodeContext="2"/>
<PassengerRPHs ListOfPassengerRPH="1 2"/>
</CabinAvailability>
<FlightSegments/>
</Flight>
</ItineraryItem>
<ItineraryItem RPH="3" Status="Available">
<Accommodation DestinationCode="DJE">
<Identity HotelName="CLUB ELDORADOR ALADIN"/>
<DateRange Start="2010-01-03" Duration="P7D" End="2010-01-10"/>
<RoomProfiles>
<RoomProfile RPH="1" RoomTypeCode="2A" BookingCode="58333A">
<RoomAmenity>BD,WC,BT,KA,HH,</RoomAmenity>
<PassengerRPHs ListOfPassengerRPH="1 2"/>
</RoomProfile>
</RoomProfiles>
<MealPlans>
<MealPlan ListOfRoomRPH="1" RPH="1" Code="AI"/>
</MealPlans>
</Accommodation>
</ItineraryItem>
</ItineraryItems>
<Cautions>
<Caution End="2009-10-14" ID="Option" Type="PackageDetail"/>
</Cautions>
<CostSummary>
<CostingItems>
<CostingItem CostBasis="7" Description="Per Person" PassengerRPH="1">
<UnitCost Amount="439.00"/>
</CostingItem>
<CostingItem CostBasis="7" Description="Per Person" PassengerRPH="2">
<UnitCost Amount="439.00"/>
</CostingItem>
<CostingItem CostBasis="26" Description="PRIX DE BASE SEJOUR" Quantity="2" InventoryItemRPH="3">
<UnitCost CurrencyCode="EUR" Amount="439.00"/>
<ExtendedCost CurrencyCode="EUR" Amount="878.00"/>
</CostingItem>
</CostingItems>
<GrossAmount Amount="878.00" CurrencyCode="EUR"/>
</CostSummary>
</Package>
<ContactDetail/>
<PassengerListItems>
<PassengerListItem RPH="1" Code="10" Gender="Male">
<Name>
<GivenName>EEEE</GivenName>
<Surname>WWWW</Surname>
</Name>
</PassengerListItem>
<PassengerListItem RPH="2" Code="10" Gender="Female">
<Name>
<GivenName>SSSSSSSSSSS</GivenName>
<Surname>WWWW</Surname>
</Name>
</PassengerListItem>
</PassengerListItems>
<InvoiceDetail/>
</PackageReservation>
</OTA_TT_PkgBookRS>
The script works fine on XML1, but not on XML2.
Where is the problem?