A
Aidan
Hi,
I have an XML file I'm trying to prep for viewing through a web-browser
using XSL. I have sucessfully applied the stylesheet to the XML file, and
it displays, but I'm unable to properly test element values using
<xsl:choose> and <xsl:when> control structures.
Here's an example of what my XML file looks like:
========= XML =========
<zonecheck>
<domain>
<fqdn>fully-qualified-domain-name.com</fqdn>
<arecords>
<valid>false</valid>
</arecords>
<mxrecords>
<valid>true</valid>
<address>152.89.132.250</address>
</mxrecords>
<nsrecords>
<valid>false</valid>
</nsrecords>
</domain>
<domain>
.....
.....
</domain>
</zonecheck>
========= XML =========
And here is the stylesheet:
======Stylesheet=======
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" type="text/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>DNS report</title>
</head>
<body>
<table>
<tr>
<th>Domain</th><th>A Records</th><th>MX Records</th><th>NS Records</th>
</tr>
<xsl:for-each select="zonecheck/domain">
<xsl:sort select="fqdn" />
<tr>
<td><xsl:value-of select="fqdn" /></td>
<xsl:choose>
<xsl:when test="arecords/valid = 'true'">
<td bgcolor="00ff33"><xsl:value-of select="arecords/valid"
/></td>
</xsl:when>
<xsl:when test="arecords/valid = 'false'">
<td bgcolor="ff0033"><xsl:value-of select="arecords/valid"
/></td>
</xsl:when>
<xsltherwise>
<td><xsl:value-of select="arecords/valid" /></td>
</xsltherwise>
</xsl:choose>
<xsl:choose>
<!-- same structure as above for mxrecords -->
</xsl:choose>
<xsl:choose>
<!-- same structure as above for nsrecords -->
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
======Stylesheet=======
The file displays in Mozilla (I care less about IE), but it never contains
any of the extra colors that the <xsl:choose> structure is trying to add (in
other words, it always uses the <xsltherwise> option). As far as I can
tell, the problem is with my knowledge of XPath, and I'm wondering if some
XML genius out there can point out what I have done wrong in my stylesheet.
Thanks in advance...
Aidan
I have an XML file I'm trying to prep for viewing through a web-browser
using XSL. I have sucessfully applied the stylesheet to the XML file, and
it displays, but I'm unable to properly test element values using
<xsl:choose> and <xsl:when> control structures.
Here's an example of what my XML file looks like:
========= XML =========
<zonecheck>
<domain>
<fqdn>fully-qualified-domain-name.com</fqdn>
<arecords>
<valid>false</valid>
</arecords>
<mxrecords>
<valid>true</valid>
<address>152.89.132.250</address>
</mxrecords>
<nsrecords>
<valid>false</valid>
</nsrecords>
</domain>
<domain>
.....
.....
</domain>
</zonecheck>
========= XML =========
And here is the stylesheet:
======Stylesheet=======
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" type="text/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>DNS report</title>
</head>
<body>
<table>
<tr>
<th>Domain</th><th>A Records</th><th>MX Records</th><th>NS Records</th>
</tr>
<xsl:for-each select="zonecheck/domain">
<xsl:sort select="fqdn" />
<tr>
<td><xsl:value-of select="fqdn" /></td>
<xsl:choose>
<xsl:when test="arecords/valid = 'true'">
<td bgcolor="00ff33"><xsl:value-of select="arecords/valid"
/></td>
</xsl:when>
<xsl:when test="arecords/valid = 'false'">
<td bgcolor="ff0033"><xsl:value-of select="arecords/valid"
/></td>
</xsl:when>
<xsltherwise>
<td><xsl:value-of select="arecords/valid" /></td>
</xsltherwise>
</xsl:choose>
<xsl:choose>
<!-- same structure as above for mxrecords -->
</xsl:choose>
<xsl:choose>
<!-- same structure as above for nsrecords -->
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
======Stylesheet=======
The file displays in Mozilla (I care less about IE), but it never contains
any of the extra colors that the <xsl:choose> structure is trying to add (in
other words, it always uses the <xsltherwise> option). As far as I can
tell, the problem is with my knowledge of XPath, and I'm wondering if some
XML genius out there can point out what I have done wrong in my stylesheet.
Thanks in advance...
Aidan