Reputation: 13
<xsl:for-each select="A">
<tr>
<xsl:choose>
<xsl:when test="@a='True'">
<td bgcolor="#FFFF00"><xsl:value-of select="../@e"/></td>
<td bgcolor="#FFFF00"><xsl:value-of select="../@b"/></td>
<td bgcolor="#999999"><xsl:value-of select="@be"/></td>
<xsl:for-each select="T">
<td bgcolor="#FFFF00"><xsl:value-of select="@o"/></td>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<td bgcolor="#999999"><xsl:value-of select="../@e"/></td>
<td bgcolor="#999999"><xsl:value-of select="../@b"/></td>
<td bgcolor="#999999"><xsl:value-of select="@be"/></td>
<xsl:for-each select="T">
<td bgcolor="#999999"><xsl:value-of select="@o"/></td>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</tr>
This part of my xslt makes the rows of a table.
The columns are ../@e, ../@b, @be, @o
For each A element, I create a row at the table.
The cells of the 3rd column have white background color no matter what.
So: First of all the first 2 columns are not full and ONLY the first cell of the first TWO COLUMNS have to be full. All the other cells of them are empty.
BUT if there is at least one @i attribute in any A element that is True, the cells of the first 2 columns (1ST ROW) have to be yellow to indicate that there is a @i that's True.
Please help me to figure it out. It has turned into a nightmare the last few days. Thank you in advance.
The full XSLT transformation is this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<!-- param values may be changed during the XSL Transformation -->
<xsl:param name="shared_item_name"> Animal </xsl:param>
<xsl:param name="description"> Birth </xsl:param>
<xsl:param name="properties"> Kind </xsl:param>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Problem</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="AA">
<table border="1" cellspacing="0">
<tr bgcolor="#9acd32">
<th> <xsl:value-of select="$shared_item_name" /> </th>
<th> <xsl:value-of select="$description" /> </th>
<th> <xsl:value-of select="$properties" /> </th>
<xsl:for-each select="IRO[position()=1]/P[position()=1]/T">
<th> <xsl:value-of select="@s" /> </th>
</xsl:for-each>
</tr>
<xsl:for-each select="AI">
<xsl:for-each select="A">
<tr>
<xsl:if test="position()=1">
<td><xsl:value-of select="../@e"/></td>
<td bgcolor="#999999"><xsl:value-of select="../@b"/></td>
</xsl:if>
<xsl:if test="not(position()=1)">
<td></td>
<td></td>
</xsl:if>
<td bgcolor="#999999"><xsl:value-of select="@be"/></td>
<xsl:choose>
<xsl:when test="@a='True'">
<xsl:for-each select="T">
<td bgcolor="#FFFF00"><xsl:value-of select="@o"/></td>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="T">
<td bgcolor="#999999"><xsl:value-of select="@o"/></td>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
<xsl:for-each select="AI">
<xsl:for-each select="A">
<tr>
<xsl:choose>
<xsl:when test="@i='True'">
<td bgcolor="#FFFF00"><xsl:value-of select="../@e"/></td>
<td bgcolor="#FFFF00"><xsl:value-of select="../@b"/></td>
<td bgcolor="#999999"><xsl:value-of select="@be"/></td>
<xsl:for-each select="T">
<td bgcolor="#FFFF00"><xsl:value-of select="@o"/></td>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<td bgcolor="#999999"><xsl:value-of select="../@e"/></td>
<td bgcolor="#999999"><xsl:value-of select="../@b"/></td>
<td bgcolor="#999999"><xsl:value-of select="@be"/></td>
<xsl:for-each select="T">
<td bgcolor="#999999"><xsl:value-of select="@o"/></td>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0
Views: 3106
Reputation: 501
With the additional reqts:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:param name="shared_item_name"> Shared Item Name </xsl:param>
<xsl:param name="description"> Description </xsl:param>
<xsl:param name="properties"> Properties </xsl:param>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Problem</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="IR">
<table border="1" cellspacing="0">
<tr bgcolor="#9acd32">
<th> <xsl:value-of select="$shared_item_name" /> </th>
<th> <xsl:value-of select="$description" /> </th>
<th> <xsl:value-of select="$properties" /> </th>
<xsl:for-each select="IRO[1]/P[1]/T">
<th> <xsl:value-of select="@s" /> </th>
</xsl:for-each>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="/IR/IRO/P">
<tr>
<xsl:choose>
<xsl:when test='count(preceding-sibling::P)=0'>
<xsl:variable name='c'>
<xsl:choose>
<xsl:when test='(@i="True") or (count(following-sibling::P[@i="True"]) > 0)'>
<xsl:choose>
<xsl:when test='count(../descendant::P[@i="True"]) > 0'>#ff0000</xsl:when>
<xsl:otherwise>#FFFF00</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test='count(../descendant::P[@i="True"]) > 0'>#FF6600</xsl:when>
<xsl:otherwise>#999999</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<td><xsl:attribute name='bgcolor'><xsl:value-of select='$c' /></xsl:attribute><xsl:value-of select='../@n' /></td>
<td><xsl:attribute name='bgcolor'><xsl:value-of select='$c' /></xsl:attribute></td>
<td bgcolor="#999999"><xsl:value-of select='@dn' /></td>
</xsl:when>
<xsl:otherwise>
<td></td>
<td></td>
<td bgcolor="#999999"><xsl:value-of select='@dn' /></td>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="/IR/IRO/IRO/P">
<tr>
<xsl:choose>
<xsl:when test='count(preceding-sibling::P)=0'>
<xsl:variable name='c'>
<xsl:choose>
<xsl:when test='(@i="True") or (count(following-sibling::P[@i="True"]) > 0)'>#FFFF00</xsl:when>
<xsl:otherwise>#999999</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<td><xsl:attribute name='bgcolor'><xsl:value-of select='$c' /></xsl:attribute><xsl:value-of select='../@n' /></td>
<td><xsl:attribute name='bgcolor'><xsl:value-of select='$c' /></xsl:attribute></td>
<td bgcolor="#999999"><xsl:value-of select='@dn' /></td>
</xsl:when>
<xsl:otherwise>
<td></td>
<td></td>
<td bgcolor="#999999"><xsl:value-of select='@dn' /></td>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="T">
<td>
<xsl:attribute name='bgcolor'>
<xsl:choose>
<xsl:when test='../@i="True"'>#FFFF00</xsl:when>
<xsl:otherwise>#999999</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select='@v' />
</td>
</xsl:template>
</xsl:stylesheet>
In this case the templates for the 2 levels of P elements have to be distinguished
Upvotes: 0
Reputation: 501
Here's an attempt, but your request lacks some precision.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:param name="shared_item_name"> Shared Item Name </xsl:param>
<xsl:param name="description"> Description </xsl:param>
<xsl:param name="properties"> Properties </xsl:param>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Problem</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="IR">
<table border="1" cellspacing="0">
<tr bgcolor="#9acd32">
<th> <xsl:value-of select="$shared_item_name" /> </th>
<th> <xsl:value-of select="$description" /> </th>
<th> <xsl:value-of select="$properties" /> </th>
<xsl:for-each select="IRO[1]/P[1]/T">
<th> <xsl:value-of select="@s" /> </th>
</xsl:for-each>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="P">
<tr>
<xsl:choose>
<xsl:when test='count(preceding-sibling::P)=0'>
<xsl:variable name='c'>
<xsl:choose>
<xsl:when test='(@i="True") or (count(following-sibling::P[@i="True"]) > 0)'>#FFFF00</xsl:when>
<xsl:otherwise>#999999</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<td><xsl:attribute name='bgcolor'><xsl:value-of select='$c' /></xsl:attribute><xsl:value-of select='../@n' /></td>
<td><xsl:attribute name='bgcolor'><xsl:value-of select='$c' /></xsl:attribute></td>
<td bgcolor="#999999"><xsl:value-of select='@dn' /></td>
</xsl:when>
<xsl:otherwise>
<td></td>
<td></td>
<td bgcolor="#999999"><xsl:value-of select='@dn' /></td>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="T">
<td>
<xsl:attribute name='bgcolor'>
<xsl:choose>
<xsl:when test='../@i="True"'>#FFFF00</xsl:when>
<xsl:otherwise>#999999</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select='@v' />
</td>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2