Help with XSL and displaying the XML only when an is present

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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, when a location is stipulated.
<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 I get an error saying the XSL is not valid.
<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:Red; xmlns:msxsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:xslt<span style="color:Black; " <span style="color:Red; exclude-result-prefixes<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; msxsl<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; output <span style="color:Red; method<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; xml<span style="color:Black; " <span style="color:Red; indent<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yes<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; html<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; head<span style="color:Blue; ><span style="color:Blue; </<span style="color:#A31515; head<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; body<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Data/DataItems/Location<span style="color:Black; "<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; border<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; width<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 100%<span style="color:Black; " <span style="color:Red; cellpadding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 2<span style="color:Black; " <span style="color:Red; cellspacing<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; WDC-dataview-table<span style="color:Black; "
<span style="color:Red; summary<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; This table displays all current weather warnings from the Met Service. <span style="color:Black; "<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; grp-heading dataview<span style="color:Black; " <span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h3<span style="color:Blue; >Weather Warnings<span style="color:Blue; </<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; th <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; date-published<span style="color:Black; "<span style="color:Blue; >Issued On<span style="color:Blue; </<span style="color:#A31515; th<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; th <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; title<span style="color:Black; "<span style="color:Blue; >Title<span style="color:Blue; </<span style="color:#A31515; th<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; issuedOn<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; call-template <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; formatDate<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; variable<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; $issuedOn<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; a <span style="color:Red; href<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; CommunitySafetyandSupport/CivilDefence/Pages/Weather-Warnings.aspx<span style="color:Black; "<span style="color:Blue; >
Severe Weather Warning
<span style="color:Blue; </<span style="color:#A31515; a<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; body<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; html<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:Green; <!-- ## Custom date template ## -->
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; formatDate<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; param <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; date<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; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; day<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring($date, 7, 2)<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; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; year<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring($date, 1, 4)<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; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; hrs<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring($date, 9, 4)<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; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; month<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; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; monthNumber<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring($date, 5, 2)<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; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 1<span style="color:Black; "<span style="color:Blue; >January<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 2<span style="color:Black; "<span style="color:Blue; >February<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 3<span style="color:Black; "<span style="color:Blue; >March<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 4<span style="color:Black; "<span style="color:Blue; >April<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 5<span style="color:Black; "<span style="color:Blue; >May<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 6<span style="color:Black; "<span style="color:Blue; >June<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 7<span style="color:Black; "<span style="color:Blue; >Jully<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 8<span style="color:Black; "<span style="color:Blue; >August<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 9<span style="color:Black; "<span style="color:Blue; >September<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 10<span style="color:Black; "<span style="color:Blue; >October<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 11<span style="color:Black; "<span style="color:Blue; >November<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $monthNumber = 12<span style="color:Black; "<span style="color:Blue; >December<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable<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; concat($day, , $month, , $year, at , $hrs, hrs )<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:Blue; >

<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >
[/code]
Any help would be appreciated as I cant see where I am going wrong with the XSL. Thanks
PS. The xml will be as per below when there are no warnings hence why I need to test to see whether there is any locations before displaying it.
<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; DataItems<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Data<span style="color:Blue; >

[/code]
<br/>
<br/>


View the full article
 
Back
Top