Link to home
Start Free TrialLog in
Avatar of ube100
ube100Flag for United Kingdom of Great Britain and Northern Ireland

asked on

xsl question...

Hi,

This xsl file is producing the output for my current source xml and I need a bit of cosmatic. At the moment it producing the following output:

<Anteeo xmlns:ota="http://www.opentravel.org/OTA/2003/05">
  <table name="STATUS" service="" />
  <table name="HotelAvail" service="">
    <AvailHtl MaxOccupancy="" Minoccupancy="" RoomRate-1="AA" TimeStart="2009-12-27" TimeDuration="P0Y0M1DT0H0M" ID="LAXCHA-FID" VendorMessage="" AmountAfterTax="69" ResGuestRPH-1="1" CancelPenalty-1="3" />
 </table>
</Anteeo>

That shpuld be:

<Anteeo xmlns:ota="http://www.opentravel.org/OTA/2003/05">
  <table name="STATUS" service="" >
<Error AnteeoReason="All OK." ErrorCode="" ErrorText="" ErrorText2="" Code="" AppErrorSeverityLevel="" QuickIndicator="Y" />
</table>
  <table name="HotelAvail" service="">
    <AvailHtl MaxOccupancy="" Minoccupancy="" RoomRate-1="AA" TimeStart="2009-12-27" TimeDuration="P0Y0M1DT0H0M" ID="LAXCHA-FID" VendorMessage="" AmountAfterTax="69" ResGuestRPH-1="1" CancelPenalty-1="3" />
 </table>
</Anteeo>
As you can see I wanted to show bit more information that saying "Every thing o.k" so it will help us when we processing in the VB App rather than empty <table name="STATUS" service="" />.
XSLTFile1.xml
AmericaDirectAvailabilityRespons.xml
AlliedTProAvailabilityResponseRe.xml
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

i couldn't find the Errors references in your xml/xsl.
based on what logic the errors attributes should be created?
Avatar of ube100

ASKER

This is normal XML produced if there is no error or nothing wrong so the XSL should produce Table node under which it describe:

<Error AnteeoReason="All OK." ErrorCode="" ErrorText="" ErrorText2="" Code=""
And this is what we gets when we have any problem:

<?xml version="1.0" encoding="UTF-8"?>
<OTA_ErrorRS xmlns="http://www.opentravel.org/OTA/2003/05"  Version="1.0">
      <Errors>
     <Error Code="Error Code" ShortText="Error Message"/>
      </Errors>
</OTA_ErrorRS>

From which xsl will produce this:
<Error AnteeoReason="There was an error retrieving the availability." ErrorCode="34567" ErrorText="" ErrorText2="" Code=""
The one I sent to you was normal source this does not have any error node.
Here is your stylesheet corrected
errors found
1. You had no fallback for success, hence the choose construct
2. You were having the entire Errors processing outside the ota: namespace
3. You had two templates for ota:RoomStay, which is ambiguous, thus not allowed
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:ota="http://www.opentravel.org/OTA/2003/05"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output indent="yes"/>
	<xsl:strip-space elements="*"/>
	<xsl:param name="service" select="''" />
	<xsl:param name="trans" select="''" />
	<xsl:output method="xml" omit-xml-declaration="yes"/>
	<xsl:template match="/">
		<Anteeo>
			<table name="STATUS" service="{$service}">
				<!-- All error records should follow this format. If they don't change the format for 
				all error messages. -->
				<xsl:choose>
					<xsl:when test="(.//ota:Errors/ota:Error[@Code != ''])">
						<Error
							AnteeoReason="There was an error retrieving availability."
							ErrorCode="{.//ota:Errors/ota:Error/@Code}"
							ErrorText="{.//ota:Errors/ota:Error/@ShortText}"
							ErrorText2=""
							Code=""
							AppErrorSeverityLevel=""
							QuickIndicator="N"
						/>
					</xsl:when>
					<xsl:when test="(.//ota:Errors/ota:Error[@Code = '']) | .//ota:Success">		
						<Error
							AnteeoReason="All OK."
							ErrorCode=""
							ErrorText=""
							ErrorText2=""
							Code=""
							AppErrorSeverityLevel=""
							QuickIndicator="Y"
						/>
					</xsl:when>	
				</xsl:choose>
				

			</table>
			<xsl:apply-templates select=".//ota:OTA_HotelAvailRS/ota:RoomStays"/>
		</Anteeo>

	</xsl:template>

	<!-- 
	<xsl:template match="ota:Errors">
		<Error
			AnteeoReason="There was an error retrieving availability."
			ErrorCode="{/Error/Code}"
			ErrorText="{//Error/ShortText}"
			ErrorText2=""
			Code="{/Error/Code}"
			AppErrorSeverityLevel=""
			QuickIndicator="N"
				/>
	</xsl:template>

	<xsl:template match="message">
		<xsl:apply-templates />
	</xsl:template>		-->	

	<xsl:template match="alternatelistseg">
		<table name="HotelAvail" service="{$service}">
			<xsl:apply-templates />
		</table>
	</xsl:template>
	<!--	<xsl:template match="/">
		<xsl:apply-templates select="ota:OTA_HotelAvailRS/ota:RoomStays"/>
	</xsl:template>
-->
	<xsl:template match="ota:RoomStays">
		<table name="HotelAvail" service="">
			<xsl:apply-templates select="ota:RoomStay"/>
		</table>
	</xsl:template>
	<xsl:template match="ota:TimeSpan">
		<xsl:attribute name="TimeStart">
			<xsl:value-of select="@Start"/>
		</xsl:attribute>
		<xsl:attribute name="TimeDuration">
			<xsl:value-of select="@Duration"/>
		</xsl:attribute>
	</xsl:template>
	<xsl:template match="ota:Total">
		<xsl:attribute name="AmountAfterTax">
			<xsl:value-of select="@AmountAfterTax"/>
		</xsl:attribute>
		<!-- 09/12/2009 <xsl:attribute name="TimeDuration">
			<xsl:value-of select="@Duration"/>
		</xsl:attribute>		-->
	</xsl:template>
	<xsl:template match="ota:ResGuestRPHs">
		<xsl:for-each select="ota:ResGuestRPH">
			<xsl:attribute name="ResGuestRPH-{position()}">
				<xsl:value-of select="@RPH"/>
			</xsl:attribute>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="ota:RoomRates">
		<xsl:for-each select="ota:RoomRate">
			<xsl:attribute name="RoomRate-{position()}">
				<xsl:value-of select="@RatePlanCode"/>
			</xsl:attribute>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="ota:BasicPropertyInfo">
		<xsl:attribute name="ID">
			<xsl:value-of select="@HotelCodeContext"/>
		</xsl:attribute>
		<xsl:attribute name="VendorMessage">
			<xsl:value-of select="ota:VendorMessages"/>
		</xsl:attribute>
	</xsl:template>
	<xsl:template match="ota:CancelPenalties">
		<xsl:for-each select="ota:CancelPenalty">
			<xsl:attribute name="CancelPenalty-{position()}">
				<xsl:value-of select="ota:Deadline/@OffsetUnitMultiplier"/>
			</xsl:attribute>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="ota:RoomStay">
		<xsl:element name="AvailHtl">
			<xsl:attribute name="MaxOccupancy"></xsl:attribute>
			<xsl:attribute name="Minoccupancy"></xsl:attribute>
			<xsl:apply-templates select="*"/>
		</xsl:element>
	</xsl:template>

</xsl:stylesheet>

Open in new window

Avatar of ube100

ASKER

Gerton,

Its producing the following output If I get this XML source:

<OTA_HotelAvailRS>
  <Errors>
    <Error Code="75202" ShortText="No availability request found [LID=4671715743994188780]" />
  </Errors>
</OTA_HotelAvailRS>

<Anteeo xmlns:ota="http://www.opentravel.org/OTA/2003/05">
  <table name="STATUS" service="" />
</Anteeo>

As I wanted to cover the both scenario here? It gets the right output when I get the normal XML source  but with just the Error notde I'm not geeting the right output.
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ube100

ASKER

its still producing the same output.
did you take away all teh ota: form teh Errors XPath?
Avatar of ube100

ASKER

Sorry Gerton,

Thats fine!! I will award your points bit later and thank you so much for your help at late sunday evening which you will get nowhere. Are you based in the UK?
welcome,
based in Belgium by the way, but it is a snowy dark Sunday here :-)
Avatar of ube100

ASKER

Thanks you!!