To show or not to show.

admin

Administrator
Staff member
I have an XML file, with the following elements:

<cast>
<character role="major|minor">
<name>(name)</name>
<statistics>
<height>(height)</height>
<weight>(weight)</weight>
<age>(age)</age>
<gender>(gender)</gender>
<species>(species)</species>
</statistics>
<desc>(Description)</desc>
<copyright>(Character creator(s)</copyright>
</cast>

Below is my XSL sheet


<?xml version="1.0"?>
<!--
Use this in the XML file to link is with this sheet.
<?xml-stylesheet type="text/xsl" href=http://www.webdeveloper.com/forum/archive/index.php/"./characters.xsl"?>
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>A Fighter's Tale</title>
<link href=http://www.webdeveloper.com/forum/archive/index.php/"../../../CSS/setup.css" type="text/css" rel="stylesheet" />
<link href="../../../CSS/novel.css" type="text/css" rel="stylesheet" />
<style type="text/css">
dt{
margin-top:20px;
border-top:1px dotted #ff0;
padding-left:30px;
font-size:20pt;
}
th{
text-align:left;
}
caption{
font-size:16pt;
margin-top:10px;
}
table{
margin:10px 0 10px 0;
}
dl dd em{
display:block;
}
</style>
</head>
<body>
<h1>The Beryl City Chronicles</h1>
<h2>A Fighter's Tale</h2>
<h3>Dramatis Person?lt;/h3>
<div id="rating">RATED<br /><img src=http://www.webdeveloper.com/forum/archive/index.php/"../../../Graphics/Censors/14-l.gif" alt="Web 14" /></div>
<h4>Major Characters:</h4>
<h5>In order of appearance</h5>
<dl>
<xsl:for-each select="cast/character[@role='major']">
<dt><xsl:value-of select="name" /></dt>
<dd>
<xsl:if test="statistics!=''">
<table>
<caption>Statistics</caption>
<tr><th>Height:</th><td><xsl:value-of select="statistics/height" /></td></tr>
<tr><th>Weight:</th><td><xsl:value-of select="statistics/weight" /></td></tr>
<tr><th>Age:</th><td><xsl:value-of select="statistics/age" /></td></tr>
<tr><th>Gender:</th><td><xsl:value-of select="statistics/gender" /></td></tr>
<tr><th>Species:</th><td><xsl:value-of select="statistics/species" /></td></tr>
</table>
</xsl:if>
<xsl:value-of select="desc" />
<em><xsl:value-of select="name" /> ?<xsl:value-of select="copyright" /></em>
</dd>
</xsl:for-each>
</dl>
<h4 style="border-top:1px solid #ff0; margin-top:10px; padding-top:10px;">Minor Characters:</h4>
<h5>In order of appearance</h5>
<dl>
<xsl:for-each select="cast/character[@role='minor']">
<dt><xsl:value-of select="name" /></dt>
<dd>
<xsl:choose>
<xsl:when test="statistics/*=''">
</xsl:when>
<xsl:otherwise>
<table>
<caption>Statistics</caption>
<xsl:choose>
<xsl:when test="statistics/height">
</xsl:when>
<xsl:otherwise>
<tr><th>Height:</th><td><xsl:value-of select="statistics/height" /></td></tr>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="statistics/weight=''">
</xsl:when>
<xsl:otherwise>
<tr><th>Weight:</th><td><xsl:value-of select="statistics/weight" /></td></tr>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="statistics/age=''">
</xsl:when>
<xsl:otherwise>
<tr><th>Age:</th><td><xsl:value-of select="statistics/age" /></td></tr>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="statistics/gender=''">
</xsl:when>
<xsl:otherwise>
<tr><th>Gender:</th><td><xsl:value-of select="statistics/gender" /></td></tr>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="statistics/species=''">
</xsl:when>
<xsl:otherwise>
<tr><th>Species:</th><td><xsl:value-of select="statistics/species" /></td></tr>
</xsl:otherwise>
</xsl:choose>
</table>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="desc" />
<em><xsl:value-of select="name" /> copyright <xsl:value-of select="copyright" /></em>
</dd>
</xsl:for-each>
</dl>
</body>
</html>
</xsl:template>
</xsl:stylesheet>



What I want this sheet to do is, if an element within <statistics> is present, display it's contents. If it isn't, act as if the element isn't there. If <statistics> is not present, don't include the table that goes with the element at all.
 
Back
Top