XSL XML transformation not working and item not appearing for selection for HTTP server [message #1865802] |
Mon, 13 May 2024 09:33  |
Eclipse User |
|
|
|
I've been trying to figure out why my XML and XSL transformation keep failing to generate in XML originally the format was in HTML and it generated perfectly. But after I changed the output method for XSL to HTML it did not generate for me when I tried transforming
my XML
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="/(name of file).xsl"?>
<forecast queryTime="28/04/2024 10:45 AM" queryLocation="Singapore">
<weather yyyymmdd="20240411">
<year>2024</year>
<month>4</month>
<date>11</date>
<dayOfWeek>Thu</dayOfWeek>
<overall>Considerable clouds</overall>
<overallCode>cloudy</overallCode>
<highest>27</highest>
<lowest>17</lowest>
</weather>
<weather yyyymmdd="20240116">
<year>2024</year>
<month>1</month>
<date>16</date>
<dayOfWeek>Tue</dayOfWeek>
<overall>Cloudy with a thunderstorm</overall>
<overallCode>thunderstorm</overallCode>
<highest>26</highest>
<lowest>18</lowest>
</weather>
<weather yyyymmdd="20240405">
<year>2024</year>
<month>4</month>
<date>5</date>
<dayOfWeek>Fri</dayOfWeek>
<overall>Afternoon shower</overall>
<overallCode>rain</overallCode>
<highest>22</highest>
<lowest>19</lowest>
</weather>
<weather yyyymmdd="20240209">
<year>2024</year>
<month>2</month>
<date>9</date>
<dayOfWeek>Fri</dayOfWeek>
<overall>A morning shower, then rain</overall>
<overallCode>rain</overallCode>
<highest>29</highest>
<lowest>20</lowest>
</weather>
<weather yyyymmdd="20240310">
<year>2024</year>
<month>3</month>
<date>10</date>
<dayOfWeek>Sun</dayOfWeek>
<overall>Partly sunny</overall>
<overallCode>partlySunny</overallCode>
<highest>30</highest>
<lowest>21</lowest>
</weather>
<weather yyyymmdd="20240311">
<year>2024</year>
<month>3</month>
<date>11</date>
<dayOfWeek>Mon</dayOfWeek>
<overall>Plenty of sunshine</overall>
<overallCode>sunny</overallCode>
<highest>34</highest>
<lowest>20</lowest>
</weather>
</forecast>
my XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http:// www.w3.org/1999/XSL/Transform" xmlns="http:// www.w3.org/1999/xhtml">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/forecast">
<html>
<head>
<title>Testing</title>
<style>
body {
font-family: Arial, sans-serif;
}
table {
border-collapse: collapse;
table-layout: fixed;
width: 100%;
}
th, td {
border: 1px solid black;
height: 100px; /* Ensures square cells */
text-align: center;
vertical-align: middle;
}
th {
background-color: #FFD700; /* Darker yellow for top row */
font-weight: bold;
}
td:first-child {
background-color: orange; /* Leftmost column background color */
font-weight: bold;
}
.bold {
font-weight: bold;
font-size: 16px;
}
.blue {
color: blue;
}
.red {
color: red;
}
.green {
color: green;
}
</style>
</head>
<body>
<h1>Singapore [01/08/20 10:00 PM]</h1>
<table>
<tr>
<th>Date</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
<th>Sun</th>
</tr>
<xsl:for-each select="forecast/day">
<xsl:variable name="day_of_week" select="@dayOfWeek"/>
<tr>
<td><xsl:value-of select="@date"/></td>
<td>
<xsl:if test="$day_of_week='Mon'">
<xsl:call-template name="format-weather"/>
</xsl:if>
</td>
<td>
<xsl:if test="$day_of_week='Tue'">
<xsl:call-template name="format-weather"/>
</xsl:if>
</td>
<td>
</td>
<td>
<xsl:if test="$day_of_week='Thu'">
<xsl:call-template name="format-weather"/>
</xsl:if>
</td>
<td>
<xsl:if test="$day_of_week='Fri'">
<xsl:call-template name="format-weather"/>
</xsl:if>
</td>
<td>
</td>
<td>
<xsl:if test="$day_of_week='Sun'">
<xsl:call-template name="format-weather"/>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template name="format-weather">
<div class="bold">
<xsl:value-of select="concat(lowest, '° - ', highest, '°')"/>
<br/>
<img src="{overallImage}"/>
<br/>
<xsl:value-of select="overallCode"/>
<br/>
<xsl:choose>
<xsl:when test="contains(overall, 'Cloudy with a thunderstorm') or contains(overall, 'A morning shower, then rain')">
<span class="blue"><xsl:value-of select="overall"/></span>
</xsl:when>
<xsl:when test="contains(overall, 'Sunny') and @dayOfWeek='Mon'">
<span class="red"><xsl:value-of select="overall"/></span>
</xsl:when>
<xsl:when test="contains(overall, 'Partly sunny') and @dayOfWeek='Fri'">
<span class="red"><xsl:value-of select="overall"/></span>
</xsl:when>
<xsl:when test="contains(overall, 'Partly cloudy')">
<span class="red"><xsl:value-of select="overall"/></span>
</xsl:when>
<xsl:when test="contains(overall, 'Considerable clouds')">
<span class="green"><xsl:value-of select="overall"/></span>
</xsl:when>
<xsl:otherwise>
<span><xsl:value-of select="overall"/></span>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
</xsl:stylesheet>
this code is after changing my output to HTML ^^ (also I've spaced out the https links cause it limited me to not send this in this forum due to being a new user)
Adding onto that my HTTP server has also been facing issues I was not able to locate the original outputted transformation of my HTML code to the HTTP preview server on the configuration, it did not appear on the section to let me choose it either. The original output did not appear when I clicked on Edit Configuration > Common > Folder either. When I run the server it does not seem to pop up either but I can see that its running. I've already changed the port to 8080 with assistance of someone's inquiry from this forum.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03067 seconds