EDN Admin
Well-known member
Hi
I am very new to using XSL to display XML. I have received the following XML code and I need to display this within a webpage.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Data<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; DataItems<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >NewZealand<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 1<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of warning for Location 1. <span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 2<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of warning for Location 2. <span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 3<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of warning for Location 3<span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 4<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of Location 4. <span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; DataItems<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Data<span style="color:Blue; >
[/code]
I have the following xsl but it is only displaying Location 1s information (e.g. location, issued, warning and validuntil).
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; xmlns:xsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/1999/XSL/Transform<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Data/DataItems<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h2<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Location<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; h2<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; last-updated<span style="color:Black; "<span style="color:Blue; >Issued:
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Issued<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Warning<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; last-updated<span style="color:Black; "<span style="color:Blue; >This warning is valid until:
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ValidUntil<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >
[/code]
I have two questions:
<ol>
How do I display all of the items. For example I want to display location 2 and 3s details as well.
The element <issued> and <validuntil> are both date and times but how to I display it as a date and time? In Location 1, the <Issued> element is written as "201110030849" and I want to display it as "3 October 2011 at 0849 hrs".
</ol>
Thanks<br/>
<br/>
View the full article
I am very new to using XSL to display XML. I have received the following XML code and I need to display this within a webpage.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; Data<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; DataItems<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; country<span style="color:Blue; >NewZealand<span style="color:Blue; </<span style="color:#A31515; country<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 1<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of warning for Location 1. <span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 2<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of warning for Location 2. <span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 3<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of warning for Location 3<span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Location<span style="color:Blue; >Location 4<span style="color:Blue; </<span style="color:#A31515; Location<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Issued<span style="color:Blue; >201110030849<span style="color:Blue; </<span style="color:#A31515; Issued<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; ValidUntil<span style="color:Blue; >201110032100<span style="color:Blue; </<span style="color:#A31515; ValidUntil<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Warning<span style="color:Blue; >Text of Location 4. <span style="color:Blue; </<span style="color:#A31515; Warning<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; DataItems<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Data<span style="color:Blue; >
[/code]
I have the following xsl but it is only displaying Location 1s information (e.g. location, issued, warning and validuntil).
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; xmlns:xsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/1999/XSL/Transform<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Data/DataItems<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h2<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Location<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; h2<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; last-updated<span style="color:Black; "<span style="color:Blue; >Issued:
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Issued<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Warning<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; p <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; last-updated<span style="color:Black; "<span style="color:Blue; >This warning is valid until:
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ValidUntil<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; p<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >
[/code]
I have two questions:
<ol>
How do I display all of the items. For example I want to display location 2 and 3s details as well.
The element <issued> and <validuntil> are both date and times but how to I display it as a date and time? In Location 1, the <Issued> element is written as "201110030849" and I want to display it as "3 October 2011 at 0849 hrs".
</ol>
Thanks<br/>
<br/>
View the full article