?
Solved

xsl problem

Posted on 2009-12-20
11
Medium Priority
?
678 Views
Last Modified: 2013-11-18
Hi,

This xsl file is producing the wrong output when I get this xml source. ( both files are attached)

This XSL should produced this:

<Anteeo xmlns:ota="http://www.opentravel.org/OTA/2003/05">
  <table name="STATUS" service="">
    <Error AnteeoReason="There was an error retrieving availability." ErrorCode="" ErrorText="" ErrorText2="" Code="" AppErrorSeverityLevel="" QuickIndicator="N" />
  </table>
</Anteeo>

instead of this for this source XML:

<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>
</Anteeo>
AvailResponse.xml
SourceXML.xml
0
Comment
Question by:ube100
  • 6
  • 4
11 Comments
 
LVL 6

Expert Comment

by:arevuri
ID: 26094036
Looks like your source xml falls into the .//ota.Success and some issue in <xsl:when test="(.//Errors/Error[@Code != ''])">
 
try removing         | .//ota:Success in your xls, so that you may get clue of the issue
0
 

Author Comment

by:ube100
ID: 26094120
Actually that source XML should be:

<OTA_HotelAvailRS TimeStamp="2009-12-20T22:09:05" xmlns="http://www.opentravel.org/OTA/2003/05">
  <Success />
  <Warning>
    <Warning Code="75205" ShortText="No availability found for this request" />
  </Warning>
</OTA_HotelAvailRS>
This is warning message but comes as a success so we will have to handle that as a error message and notifiy the user accordingly.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26094225
The issue is that Error is in the ota namespace, and you are testing outside that namespace

I added a corrected stylesheet.

The annoying thing is that we are running in circles with your stylesheets.
First they don't work because the Success and Errors are outside the namespace, then we change that, then they are in the namespace again, a bit confusing.
The webservice you are pulling this from seems highly unreliable.
Or are you hand making these example?
<?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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26094244
You could ofcourse, if you are uncertain about the nemaspace,
make the XPaths namespace agnostic
So we are done with all these issues
<xsl:choose>
					<xsl:when test="/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Errors']/*[local-name() = '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="/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Errors']/*[local-name() = 'Error'][@Code != ''] | /ota:OTA_HotelAvailRS/*[local-name() = 'Success']">
						<Error
								AnteeoReason="All OK."
								ErrorCode=""
								ErrorText=""
								ErrorText2=""
								Code=""
								AppErrorSeverityLevel=""
								QuickIndicator="Y"
                                                />
					</xsl:when>
				</xsl:choose>

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26094355
Oh, I did not see your follow up on Warning
I added Warning to the choose
<?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="/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Errors']/*[local-name() = '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="/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Warning']/*[local-name() = 'Warning'][@Code != '']">
						<Warning
							AnteeoReason="There was a warning retrieving availability."
							ErrorCode="{/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Warning']/*[local-name() = 'Warning']/@Code}"
							ErrorText="{/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Warning']/*[local-name() = 'Warning']/@ShortText}"
							ErrorText2=""
							Code=""
							AppErrorSeverityLevel=""
							QuickIndicator="N"
						/>
					</xsl:when>
					<xsl:when test="/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Errors']/*[local-name() = 'Error'][@Code != ''] | /ota:OTA_HotelAvailRS/*[local-name() = '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
 

Author Comment

by:ube100
ID: 26094650
Hi Gerton,

It is still producing this output even though this source is with the warning node:

<table name="STATUS" service="">
    <Error AnteeoReason="All OK." ErrorCode="" ErrorText="" ErrorText2="" Code="" AppErrorSeverityLevel="" QuickIndicator="Y" />
  </table>

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26094704
well, with the source you posted, I get a different result.
Mixed up the source again?
Please post a new one then
0
 

Author Comment

by:ube100
ID: 26094726
Please find the source XML.
AmericaDirectAvailabilityRespons.xml
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 26094804
Answer: yes, you messed up the soure again

please note that you posted this as the original source
<Warning>
    <Warning Code="75205" ShortText="No availability found for this request" />

and now I find this
    <Warnings>
        <Warning Code="75205" ShortText="No availability found for this request" />

Note the extra "s"

This little errors cost me a lot of time.
If you would only do the slightest effort to try and understand the XSLTs, you could have fixed this yourself,

anyway, replace the second when branch with this
<xsl:when test="/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Warnings']/*[local-name() = 'Warning'][@Code != '']">
                        <Warning
                            AnteeoReason="There was a warning retrieving availability."
                            ErrorCode="{/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Warnings']/*[local-name() = 'Warning']/@Code}"
                            ErrorText="{/*[local-name() = 'OTA_HotelAvailRS']/*[local-name() = 'Warnings']/*[local-name() = 'Warning']/@ShortText}"
                            ErrorText2=""
                            Code=""
                            AppErrorSeverityLevel=""
                            QuickIndicator="N"
                        />
                    </xsl:when>

Open in new window

0
 

Author Closing Comment

by:ube100
ID: 31668415
Sorry for the time you have wasted. Thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 26095070
welcome,
no problem, just be carefull with posting correct sources
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question