
December 7th, 2010, 02:28 AM
|
|
|
Not use xsl:for-each
make a template is the better way
for testing i modify the xml source
make numbers by name
Code:
<?xml version="1.0"?>
<!--<?xml-stylesheet type="text/xsl" href="https://domain.name.com/db/bfunjbizz?act=dbpage^pagename=billboard2.xsl"?>
-->
<qdbapi>
<action>API_DoQuery</action>
<errcode>0</errcode>
<errtext>No error</errtext>
<dbinfo>
<name>eCard</name>
<desc></desc>
</dbinfo>
<variables>
</variables>
<chdbids>
</chdbids>
<record>
<ecard_url>https://devwww20.domain.com/test.html</ecard_url>
<recipient_name>John Doe1</recipient_name>
</record>
<record>
<ecard_url>https://devwww20.domain.com/test1.html</ecard_url>
<recipient_name>Jane Smith2</recipient_name>
</record>
<record>
<ecard_url>https://devwww20.domain.com/test2.html</ecard_url>
<recipient_name>Emily Test1</recipient_name>
</record>
<record>
<ecard_url>https://devwww20.domain.com/test3.html</ecard_url>
<recipient_name>Bugs Bunny2</recipient_name>
</record>
</qdbapi>
xsl:
Code:
<?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" indent="yes" 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:template match="/">
<html>
<head>
<!--
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-->
<title></title>
<link rel="stylesheet" type="text/css" href="http://www.domain.com/template_styles_navy.css"/>
<style type="text/css">
<!--
/* ... defined css ... */
-->
table
{
/*border-collapse:collapse;*/
}
table,th,td
{
border: 2px solid black;
width:100%;
margin:10px;
}
td
{
width:50%;
background-color:#e6e6e6;
padding:30px;
text-align:center;
}
</style>
</head>
<body>
<xsl:choose>
<xsl:when test="not(qdbapi/record)">
<!-- SHOULD ANYTHING BE DISPLAYED WHEN NO RECORDS ARE FOUND -->
<p>NO RECORDS ARE FOUND</p>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="qdbapi"/>
</xsl:otherwise>
</xsl:choose>
</body>
</html>
</xsl:template>
<xsl:template match="qdbapi">
<table>
<xsl:apply-templates select="record"/>
</table>
</xsl:template>
<xsl:template match="record">
<xsl:if test="position() mod 2 = 1">
<tr>
<td>
<xsl:attribute name="class">
<xsl:text>space</xsl:text>
</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="ecard_url"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>_blank</xsl:text>
</xsl:attribute>
<xsl:value-of select="recipient_name"/>
</xsl:element>
</td>
<xsl:call-template name="record">
<xsl:with-param name="kn" select="following::record"/>
</xsl:call-template>
</tr>
</xsl:if>
</xsl:template>
<xsl:template name="record">
<xsl:param name="kn"/>
<td>
<xsl:attribute name="class">
<xsl:text>space</xsl:text>
</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="$kn/ecard_url"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>_blank</xsl:text>
</xsl:attribute>
<xsl:value-of select="$kn/recipient_name"/>
</xsl:element>
</td>
</xsl:template>
</xsl:stylesheet>
result when record defined
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="http://www.domain.com/template_styles_navy.css">
<style type="text/css">
table
{
/*border-collapse:collapse;*/
}
table,th,td
{
border: 2px solid black;
width:100%;
margin:10px;
}
td
{
width:50%;
background-color:#e6e6e6;
padding:30px;
text-align:center;
}
</style>
</head>
<body>
<table>
<tr>
<td class="space">
<a href="https://devwww20.domain.com/test.html" target="_blank">John Doe1</a>
</td>
<td class="space">
<a href="https://devwww20.domain.com/test1.html" target="_blank">Jane Smith2</a>
</td>
</tr>
<tr>
<td class="space">
<a href="https://devwww20.domain.com/test2.html" target="_blank">Emily Test1</a>
</td>
<td class="space">
<a href="https://devwww20.domain.com/test3.html" target="_blank">Bugs Bunny2</a>
</td>
</tr>
</table>
</body>
</html>
record not defined
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="http://www.domain.com/template_styles_navy.css">
<style type="text/css">
table
{
/*border-collapse:collapse;*/
}
table,th,td
{
border: 2px solid black;
width:100%;
margin:10px;
}
td
{
width:50%;
background-color:#e6e6e6;
padding:30px;
text-align:center;
}
</style>
</head>
<body>
<p>NO RECORDS ARE FOUND</p>
</body>
</html>
__________________
Helmut Hagemann Germany
fallen to the bottom of the facts?
I reach my hand and we go together
wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage
|