create XSLT for air seat map xml



I have a AirSeatMap Resonse XML and I want to create xslt for it to display as html table Column and Row collection. I know only basics of xslt and I am not able to how I map columns and rows from xml to html table. Please guide me to solve this problem.


Here is my XML file



<OTA_AirSeatMapRS>
<SeatMapResponses>
<SeatMapResponse>
<SeatMapDetails>
<CabinClass CabinType="Economy" Name="AC DF">
<AirRows>
<AirRow RowNumber="1">
<AirSeats>
<AirSeat SeatAvailability="U" SeatNumber="A"/>
<AirSeat SeatAvailability="A" SeatNumber="C">0</AirSeat>
<AirSeat SeatAvailability="A" SeatNumber="D">0</AirSeat>
<AirSeat SeatAvailability="A" SeatNumber="F">0</AirSeat>
</AirSeats>
<AirRowCharacteristics CharacteristicList="E" />
</AirRow>
<AirRow RowNumber="2">
<AirSeats>
<AirSeat SeatAvailability="A" SeatNumber="A" >0</AirSeat>
<AirSeat SeatAvailability="A" SeatNumber="C" >0</AirSeat>
<AirSeat SeatAvailability="A" SeatNumber="D" >0</AirSeat>
<AirSeat SeatAvailability="A" SeatNumber="F" >0</AirSeat>
</AirSeats>
<AirRowCharacteristics CharacteristicList="" />
</AirRow>
</AirRows>
</CabinClass>
</SeatMapDetails>
</SeatMapResponse>
</SeatMapResponses>
</OTA_AirSeatMapRS>


I am created below xslt but its not giving expected output:


I created xslt as below per its not correct logically



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="no"/>


<xsl:template match="/">
<xsl:variable name="ColumnNames" select="OTA_AirSeatMapRS/SeatMapResponses/SeatMapResponse/SeatMapDetails/CabinClass/AirRows/AirRow/AirSeats[1][1]"/>
<xsl:variable name="RowsCollection" select="OTA_AirSeatMapRS/SeatMapResponses/SeatMapResponse/SeatMapDetails/CabinClass/AirRows/AirRow"/>
<xsl:variable name="SeatsInformation" select="OTA_AirSeatMapRS/SeatMapResponses/SeatMapResponse/SeatMapDetails/CabinClass/AirRows/AirRow/AirSeats"/>

<table class="seatmap floatLeft margin-top10">
<tr>
<th></th>
<xsl:for-each select="$ColumnNames[1]">
<xsl:variable name="no" select="AirSeat/@SeatNumber"/>
<xsl:for-each select="$no">
<th>
<label>
<xsl:value-of select="."/>
</label>
</th>
</xsl:for-each>
</xsl:for-each>
<th></th>
</tr>
<xsl:for-each select="$RowsCollection">
<xsl:variable name="CurrentRowNo" select="@RowNumber">
</xsl:variable>
<tr>
<td>
<xsl:value-of select="$CurrentRowNo"></xsl:value-of>
</td>
<xsl:for-each select="AirSeats/AirSeat">
<td>
<xsl:choose>
<xsl:when test ="@SeatAvailability='A'">
<!--Available-->
<img src="Resources/images/SeatMap/airSeatMap_Available.gif" alt="Unknown">
</img>
</xsl:when>
<xsl:when test ="@SeatAvailability='U'">
<img src="Resources/images/SeatMap/unknown.png" alt="Unknown">
</img>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@SeatAvailability"/>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:for-each>
<td>
<xsl:value-of select="$CurrentRowNo"></xsl:value-of>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

No comments:

Post a Comment