This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Newbie: See if a node exists!
- From: Americo Albuquerque <aalbuquerque at viseu dot ipiaget dot pt>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 7 Jun 2002 20:09:15 +0100
- Subject: RE: [xsl] Newbie: See if a node exists!
- Keywords: XSL-List
- Reply-to: xsl-list at lists dot mulberrytech dot com
ok. here is my xsl (it's a little big):
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Programado por: Americo Albuquerque (Chainsword)
()
_____||________________
()_____ ________________/
||
()
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:template match="/Display">
<xsl:apply-templates select="PATH"/>
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="46">
<xsl:choose>
<xsl:when test="BLOCK">
<xsl:apply-templates select="Title"/>
<tr>
<td colspan="6" width="100%"><img border="0" src="/Images/spacer.gif"
width="1" height="5"/></td>
</tr>
<xsl:apply-templates select="BLOCK"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="BOOK[@destaque=-1]">
<xsl:call-template name="Destaque"/>
<tr>
<td colspan="5" height="10"><img border="0" src="/Images/spacer.gif"
width="1" height="1"/></td>
</tr>
<tr>
<td width="20"><img border="0" src="/Images/spacer.gif" width="1"
height="1"/></td>
<td colspan="3" class="Mais2"
background="/images/dots/red_dot.gif"><img border="0"
src="/images/spacer.gif" width="1" height="1"/></td>
</tr>
</xsl:if>
<xsl:apply-templates select="Title"/>
<xsl:call-template name="BookHeader"/>
<xsl:apply-templates select="BOOK[not (@destaque=-1)]"/>
</xsl:otherwise>
</xsl:choose>
</table>
</xsl:template>
<xsl:template match="PATH">
<script language="JavaScript">
<xsl:if test="@img">
Preview.src = "<xsl:value-of select="@img"/>";
NullPreview.value = "<xsl:value-of select="@img"/>";
</xsl:if>
title.innerText = "<xsl:value-of select="@name"/>";
</script>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="10"><img border="0" src="imagens/spacer.gif" width="1"
height="1"/></td>
<td><a Class="Mais2" href="/">Editora Piaget</a> > <a Class="Mais2"
href="{@name}" onclick="return false;"><xsl:value-of
select="@name"/></a></td>
<td width="3%"><img border="0" src="imagens/spacer.gif" width="1"
height="1"/></td>
</tr>
<tr>
<td height="18" colspan="3"><img border="0" src="/Images/spacer.gif"
width="1" height="1"/></td>
</tr>
</table>
</xsl:template>
<xsl:template match="BLOCK">
<xsl:call-template name="Title">
<xsl:with-param name="name" select="@name"/>
<xsl:with-param name="bgcolor">white</xsl:with-param>
<xsl:with-param name="class">blockHeader</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="BookHeader">
<xsl:with-param name="ht" select="15"/>
</xsl:call-template>
<xsl:apply-templates select="BOOK[not (@destaque=-1)]"/>
</xsl:template>
<xsl:template match="Title[@Filter=-1]">
<tr>
<td colspan="5"><table border="0" cellpadding="0" cellspacing="0"
width="100%" height="10">
<tr>
<td class="Filter">Filtro:</td>
<td align="right"><input type="button" class="Filter" value="Todos"
onclick="ReloadList('?View={/Display/CONFIG/@View}&List={/Display/CONFIG
/@List}')"/></td>
<xsl:call-template name="repeater">
<xsl:with-param name="i" select="26"/>
</xsl:call-template>
</tr>
</table></td>
</tr>
<tr>
<td colspan="5" class="title"
background="/images/dots/red_dot.gif"><xsl:value-of select="@name"/></td>
</tr>
</xsl:template>
<xsl:template name="Title" match="Title">
<xsl:param name="name" select="@name"/>
<xsl:param name="bgcolor">/images/dots/red_dot.gif</xsl:param>
<xsl:param name="class">title</xsl:param>
<tr>
<td colspan="5" class="{$class}" background="{$bgcolor}"><xsl:value-of
select="$name"/></td>
</tr>
</xsl:template>
<xsl:template match="BOOK[not (@destaque=-1)]">
<tr onmouseover="Shadow(this,'gray');" onmouseout="Shadow(this,'');">
<td width="20"><img border="0" src="/Images/spacer.gif" width="1"
height="1"/></td>
<td width="14%" class="Mais2"><xsl:value-of select="@code"/></td>
<td><a class="Mais2" href="livro.asp?BOOK={@ID}"><xsl:value-of
select="@title"/></a></td>
<td width="14%" class="ISBN" align="center"><xsl:value-of
select="@ISBN"/></td>
<td width="2%"><img border="0" src="/Images/spacer.gif" width="1"
height="1"/></td>
</tr><tr>
<td colspan="6" width="100%"><img border="0" src="/Images/spacer.gif"
width="1" height="5"/></td>
</tr>
</xsl:template>
<xsl:template match="BOOK[@destaque=-1]">
<xsl:param name="color">silver</xsl:param>
<tr>
<xsl:if test="position() mod 2=0">
<xsl:attribute name="bgcolor"><xsl:value-of
select="$color"/></xsl:attribute>
</xsl:if>
<td rowspan="3" width="10"><img border="0" src="/images/spacer.gif"
width="10" height="1"/></td>
<td width="14%" class="Mais2" valign="bottom"><xsl:value-of
select="@code"/></td>
<td class="Mais2" valign="bottom"><a class="Mais2"
href="livro.asp?BOOK={@ID}"><xsl:value-of select="@title"/></a></td>
<td width="14%" class="ISBN" valign="bottom" align="center"><span
class="ISBN"><xsl:value-of select="@ISBN"/></span></td>
<td class="Mais2" rowspan="3" width="37" valign="bottom" align="right"><A
class="Book" href="about:{@title}" onclick="return
OpenBigPicture({@ID});"><img src="{@cover}" alt="Sem Imagem"
title="{@title}" width="35" height="50"/></A></td>
<td rowspan="3" width="10"><img border="0" src="/images/spacer.gif"
width="10" height="1"/></td>
</tr><tr>
<xsl:if test="position() mod 2=0">
<xsl:attribute name="bgcolor"><xsl:value-of
select="$color"/></xsl:attribute>
</xsl:if>
<td class="bold">Autor(es):</td>
<td colspan="2" class="Mais2"><xsl:apply-templates select="Author"/></td>
</tr><tr>
<xsl:if test="position() mod 2=0">
<xsl:attribute name="bgcolor"><xsl:value-of
select="$color"/></xsl:attribute>
</xsl:if>
<td colspan="3" class="Mais2"><img border="0" src="/images/spacer.gif"
width="1" height="1"/></td>
</tr><tr>
<td colspan="4" height="2"><img border="0" src="/images/spacer.gif"
width="1" height="1"/></td>
</tr>
</xsl:template>
<xsl:template match="Author">
<A class="Author" href="autor.asp?ID={@ID}"
title="{@biografy}"><xsl:value-of select="@name"/></A>
<xsl:if test="position() < last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="Destaque">
<tr>
<td width="20" valign="top" height="15"><img border="0"
src="/Images/spacer.gif" width="1" height="1"/></td>
<td colspan="4" bgcolor="#A53131" class="title">Destaques</td>
</tr>
<xsl:apply-templates select="BOOK[@destaque=-1]"/>
</xsl:template>
<xsl:template name="BookHeader">
<xsl:param name="ht" select="27"/>
<tr>
<td width="20" valign="top" height="{$ht}"><img border="0"
src="/Images/spacer.gif" width="1" height="1"/></td>
<td width="14%" valign="bottom" align="left" height="{$ht}"
class="bold">Codigo</td>
<td valign="bottom" align="left" height="{$ht}" class="bold">Titulo</td>
<td width="16%" valign="bottom" align="center" height="27"
class="bold">ISBN</td>
<td width="2%" valign="top" height="{$ht}"><img border="0"
src="/Images/spacer.gif" width="1" height="1"/></td>
</tr>
</xsl:template>
<xsl:template name="repeater">
<xsl:param name="i">26</xsl:param>
<xsl:if test="$i > 0">
<xsl:call-template name="repeater">
<xsl:with-param name="i" select="$i - 1"/>
</xsl:call-template>
<td align="right"><input type="button" class="Filter"
onclick="ReloadList('?View={/Display/CONFIG/@View}&List={/Display/CONFIG
/@List}&Filter={substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ',$i,1)}')">
<xsl:attribute name="value"><xsl:value-of
select="substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ',$i,1)" /></xsl:attribute>
</input></td>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
and here is my xml (isauto generated from an ASP page)
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type='text/xsl' href='display.xsl'?>
<Display total="3"><PATH name="Autores"/>
<Title name="Autores" Filter="-1"/>
<BLOCK name="{@*[name() = BOOK/Author/@name}">
<BOOK title="Metodologia da Recolha de Dados" ID="1494" code="ES 098"
ISBN="972-771-074-3" cover="">
<Author name="Jean-Marie de Ketele" ID="1223" biografy="E professor no
Laboratorio de Pedagogia Experimental da Universidade de Louvain-la-Neuve e
colaborador do Centro Internacional Francofono para a Educacao em
Quimica."/>
</BOOK>
</BLOCK>
<BLOCK name="{@*[name() = BOOK/Author/@name}">
<BOOK title="Bacterias, Virus e Fungos" ID="1030" code="BBCC 086"
ISBN="972-771-260-6" cover="">
<Author name="Laurence Rolland" ID="1653" biografy="Doutora em Biologia
Humana, investiga na area da imunologia parasitaria e da biologia molecular
dos parasitas."/>
</BOOK>
</BLOCK>
<BLOCK name="{@*[name() = BOOK/Author/@name}">
<BOOK title="Atitudes e Valores no Ensino" ID="947" code="HP 075"
ISBN="972-771-350-5" cover="">
<Author name="Felipe Trillo " ID="822" biografy=""/>
<Author name="Antonio Bolivar" ID="1627" biografy=""/>
<Author name="Fernando Cabral Pinto" ID="1150" biografy="E mestre em
Filosofia Contemporanea pela Faculdade de Letras da Universidade de Coimbra
e doutor em Ciencias da Educacao pela Faculdade de Psicologia e Ciencias da
Educacao da Universidade do Porto. Exerce actualmente funcoes docentes e
directivas no Complexo de Ensino Superior Jean Piaget, de Vila Nova de
Gaia."/>
<Author name="Jose Antonio Caride" ID="1628" biografy=""/>
</BOOK>
</BLOCK>
<CONFIG ID="26" Start="1" QNT="20" Filter="X" View="Autores"
List="Autores"/>
</Display>
but since it is a self generated xml, I've changed the code that create the
xml so I get this xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type='text/xsl' href='display.xsl'?>
<Display total="3"><PATH name="Autores"/>
<Title name="Autores" Filter="-1"/>
<BLOCK name="Xavier Roegiers">
<BOOK title="Metodologia da Recolha de Dados" ID="1494" code="ES 098"
ISBN="972-771-074-3" cover="">
<Author name="Jean-Marie de Ketele" ID="1223" biografy="E professor no
Laboratorio de Pedagogia Experimental da Universidade de Louvain-la-Neuve e
colaborador do Centro Internacional Francofono para a Educacao em
Quimica."/>
</BOOK>
</BLOCK>
<BLOCK name="Xavier Rolland">
<BOOK title="Bacterias, Virus e Fungos" ID="1030" code="BBCC 086"
ISBN="972-771-260-6" cover="">
<Author name="Laurence Rolland" ID="1653" biografy="Doutora em Biologia
Humana, investiga na area da imunologia parasitaria e da biologia molecular
dos parasitas."/>
</BOOK>
</BLOCK>
<BLOCK name="Xose Rubal">
<BOOK title="Atitudes e Valores no Ensino" ID="947" code="HP 075"
ISBN="972-771-350-5" cover="">
<Author name="Felipe Trillo " ID="822" biografy=""/>
<Author name="Antonio Bolivar" ID="1627" biografy=""/>
<Author name="Fernando Cabral Pinto" ID="1150" biografy="E mestre em
Filosofia Contemporanea pela Faculdade de Letras da Universidade de Coimbra
e doutor em Ciencias da Educacao pela Faculdade de Psicologia e Ciencias da
Educacao da Universidade do Porto. Exerce actualmente funcoes docentes e
directivas no Complexo de Ensino Superior Jean Piaget, de Vila Nova de
Gaia."/>
<Author name="Jose Antonio Caride" ID="1628" biografy=""/>
</BOOK>
</BLOCK>
<CONFIG ID="26" Start="1" QNT="20" Filter="X" View="Autores"
List="Autores"/>
</Display>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list