• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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
0
ube100
Asked:
ube100
  • 5
  • 5
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
i couldn't find the Errors references in your xml/xsl.
based on what logic the errors attributes should be created?
0
 
ube100Author Commented:
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.
0
 
Geert BormansCommented:
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ube100Author Commented:
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.
0
 
Geert BormansCommented:
It is incredibly weird that  the webservice returns responses in different namespaces.
I think it is a design flaw from the web service, but apparently Success is in the ota namespace and Error is not...
this is very, very weird
Anyway, simply remove  the ota: prfixes from the XPaths in the Error part
                               <xsl:choose> 
                                        <xsl:when test="(.//Errors/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="(.//Errors/Error[@Code = '']) | .//ota:Success">                 
                                                <Error 
                                                        AnteeoReason="All OK." 
                                                        ErrorCode="" 
                                                        ErrorText="" 
                                                        ErrorText2="" 
                                                        Code="" 
                                                        AppErrorSeverityLevel="" 
                                                        QuickIndicator="Y" 
                                                /> 
                                        </xsl:when>      
                                </xsl:choose> 

Open in new window

0
 
ube100Author Commented:
its still producing the same output.
0
 
Geert BormansCommented:
did you take away all teh ota: form teh Errors XPath?
0
 
ube100Author Commented:
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?
0
 
Geert BormansCommented:
welcome,
based in Belgium by the way, but it is a snowy dark Sunday here :-)
0
 
ube100Author Commented:
Thanks you!!
0
 
Geert BormansCommented:
welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now