[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

IE Client XSL

The following is a partial example of the XML data.

<resource>
<name>Doe, John</name>
 <year>
<month id=”May”>
<day id=”050106”><start>Unavailable</start><stop>Unavailable</stop></day>
<day id=”050206”><start>Unavailable</start><stop>Unavailable</stop></day>
<day id=”050306”><start>07:00:00</start><stop>15:30:00</stop></day>
<day id=”050406”><start>07:00:00</start><stop>15:30:00</stop></day>
<day id=”050506”><start>07:00:00</start><stop>15:30:00</stop></day>
<day id=”050606”><start>07:00:00</start><stop>15:30:00</stop></day>
<day id=”050706”><start>Vacation</start><stop>Vacation</stop></day>
</month>
<month id="June">
</month>
</year>
</resource>

I need a transformation to make the data look like the following in table format:


Name:  Doe, John
Date                                Start               End
Monday, May 01, 2006      07:00:00         15:30:00
Sunday, May 07, 2006      Unavailable       Unavailable

0
spotmoose
Asked:
spotmoose
  • 5
  • 5
1 Solution
 
Geert BormansCommented:
Hi spotmoose,

something like this will get you started

you will need to find a solution for the date processing though

I will send some links of previous questions on that topic in a minute

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <html>
            <head></head>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
   
    <xsl:template match="name">
        <p><xsl:text>Name: </xsl:text><xsl:value-of select="."/></p>
    </xsl:template>
   
    <xsl:template match="month">
        <table>
            <tr><th>Date</th><th>start</th><th>end</th></tr>
            <xsl:apply-templates/>
        </table>
    </xsl:template>
   
    <xsl:template match="day">
        <tr>
            <td><xsl:value-of select="@id"/></td>
            <td><xsl:value-of select="start"/></td>
            <td><xsl:value-of select="stop"/></td>
        </tr>
    </xsl:template>
</xsl:stylesheet>


Cheers!
0
 
spotmooseAuthor Commented:
Using the following xml file with the xsl:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="test.xsl"?>
<resource>
<name>Doe, John</name>
 <year>
<month id="May">
<day id="050106"><start>Unavailable</start><stop>Unavailable</stop></day>
<day id="050206"><start>Unavailable</start><stop>Unavailable</stop></day>
<day id="050306"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="050406"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="050506"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="050606"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="050706"><start>Vacation</start><stop>Vacation</stop></day>
</month>
<month id="June">
<day id="060106"><start>Unavailable</start><stop>Unavailable</stop></day>
<day id="060206"><start>Unavailable</start><stop>Unavailable</stop></day>
<day id="060306"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="060406"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="060506"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="060606"><start>07:00:00</start><stop>15:30:00</stop></day>
<day id="060706"><start>Vacation</start><stop>Vacation</stop></day>
</month>
</year>
</resource>



I get the following (two lines of data not in a table format):

Doe, John UnavailableUnavailable UnavailableUnavailable 07:00:0015:30:00 07:00:0015:30:00 07:00:0015:30:00 07:00:0015:30:00 VacationVacation UnavailableUnavailable UnavailableUnavailable 07:00:0015:30:00 07:00:0015:30:00 07:00:0015:30:00 07:00:0015:30:00 VacationVacation
0
 
Geert BormansCommented:
spotmoose,
> <?xml-stylesheet type="text/css" href="test.xsl"?>

well, you get the data, tags stripped, because the XSLT is not called
you have to correct the above line to expect a XSLT instead of a CSS

<?xml-stylesheet type="text/xsl" href="test.xsl"?>
will work

cheers

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.

 
Geert BormansCommented:
spotmoose,

I changed the last template and added a named template,
in order to normalise the Date

    <xsl:template match="day">
        <tr>
            <td>
                <xsl:call-template name="normaliseDate">
                    <xsl:with-param name="curDate" select="@id"/>
                </xsl:call-template>
            </td>
            <td><xsl:value-of select="start"/></td>
            <td><xsl:value-of select="stop"/></td>
        </tr>
    </xsl:template>
   
    <xsl:template name="normaliseDate">
        <xsl:param name="curDate"/>
        <xsl:text>20</xsl:text>
        <xsl:value-of select="substring($curDate, 5,2)"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="substring($curDate, 1,2)"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="substring($curDate, 3,2)"/>
    </xsl:template>
0
 
spotmooseAuthor Commented:
sorry for the problem I induced

works and adjusted table to have border.  Thanks.  The links to the date part of the question would be appreciated.

However, if you can't find the links is there a way to make the date look like 05/01/06  will be just as good for what I need
0
 
spotmooseAuthor Commented:
Works!

I would like somthing similiar to Monday, May 01, 2006

But beggar can't be choosy!

I will close the quest and give you the points.   However, if you can provide any links or simliar format let me know.
0
 
spotmooseAuthor Commented:
Great help and support.  Quick and allowed me to make a mistake without hammering me.
0
 
Geert BormansCommented:
spotmoose,
> date look like 05/01/06

change the named template into

   <xsl:template name="normaliseDate">
        <xsl:param name="curDate"/>
        <xsl:value-of select="substring($curDate, 1,2)"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="substring($curDate, 3,2)"/>
        <xsl:text>/</xsl:text>
        <xsl:value-of select="substring($curDate, 5,2)"/>
    </xsl:template>

There is no standard functionality in XSLT1.0 to get the weekday of a certain date for example
(well you can plug in a template that does the entire calculation, with leap years and all that)
So it requires some workarounds to get there (and some are not XSLT processor independent)

if you want to see what it takes,
you can look at www.exslt.org in the dates section
exslt is a standardisation effort for xslt extensions

here is an answer I gave to an earlier question that uses a template from exslt

cheers
0
 
spotmooseAuthor Commented:
Thanks!  I really appreciate the help.
0
 
Geert BormansCommented:
you are welcome

it just occurs to me that I forgot to paste the URL of the question
here it is
http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21850319.html

cheers
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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