|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Please have a look and tell me wether what i'm trying to do is impossible or if i'm just using wrong means...
my problem is that: Code:
<xsl:if test="$search != ''"> <xsl:for-each select="database/computer[$search = $searchparam]"> if i write the following line it works: Code:
<xsl:for-each select="database/computer[@owner = $searchparam]"> now i wonder: why does using with a variable work in xsl:if but if i try to use it on the left side of xsl:for-each it doesn't? Attachments: this is an excerpt from my xml-file: Code:
<database> <computer id="1" owner="zyrill" hostname="" update="2003/5/19"> <hardware> <case>Desktop</case> <cpu> <name speed="700">Athlon</name> </cpu> <harddisc> <name size="17.1">Quantum Atlas 10K 18WLS SCSI</name> </harddisc> <ram type="SDR">128</ram> <drives> <name type="CD">Plextor PX-12TS SCSI</name> </drives> <monitor>Step</monitor> <printer></printer> <scanner></scanner> <etc> <name></name> </etc> </hardware> <software> <os>Win2K</os> <application> <name>Office 2000</name> <name>SilkRadar</name> <name>TightVNC</name> <name>VirusScan</name> </application> </software> </computer> </database> and this is the xsl-file i'm using to render it: Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="ISO-8859-1" doctype-public="-//w3c//dtd html 4.0 transitional//en" />
<xsl:param name="search">@owner</xsl:param>
<xsl:param name="searchparam">krueger</xsl:param>
<xsl:param name="sort"></xsl:param>
<xsl:template match="/">
<html>
<head>
<title>Database of hard- & sofware</title>
<style type="text/css">
td { font-family: arial; font-size: 8pt; }
.AreaHeader1 { background-color: #FF7A37; text-align: center; }
.AreaHeader2 { background-color: #FCDC48; text-align: center; }
.AreaHeader3 { background-color: #48A5FC; text-align: center; }
.HeaderCell1 { background-color: #F5D4A5; }
.HeaderCell2 { background-color: #F3C37E; }
.HeaderCell3 { background-color: #FEFBCE; }
.HeaderCell4 { background-color: #FFFAAB; }
.HeaderCell5 { background-color: #DDEEFF; }
.HeaderCell6 { background-color: #BBDDFF; }
.Cell1 { background-color: #DDDDDD; }
.Cell2 { background-color: #EEEEEE; }
</style>
</head>
<body>
<xsl:if test="$search != ''">
<xsl:for-each select="database/computer[$search = $searchparam]">
<table border="0" cellpadding="4" width="100%">
<tr>
<td Class="AreaHeader1" colspan="3">Information about Computer:</td>
<td Class="AreaHeader2" colspan="9">Hardware:</td>
<td Class="AreaHeader3" colspan="2">Software:</td>
</tr>
<tr>
<td Class="HeaderCell1">Owner and Computer ID</td>
<td Class="HeaderCell2">Hostname</td>
<td Class="HeaderCell1">Dataset last updated:</td>
<td class="HeaderCell3">Case</td>
<td class="HeaderCell4">CPU(s)</td>
<td class="HeaderCell3">Harddisc(s)</td>
<td class="HeaderCell4">RAM</td>
<td class="HeaderCell3">Drive(s)</td>
<td class="HeaderCell4">Monitor</td>
<td class="HeaderCell3">Printer</td>
<td class="HeaderCell4">Scanner</td>
<td class="HeaderCell3">etc</td>
<td Class="HeaderCell5">OS</td>
<td Class="HeaderCell6">Application(s)</td>
</tr>
<tr>
<td Class="Cell1"><xsl:value-of select="@owner"/> (<xsl:value-of select="@id"/>)</td>
<td Class="Cell2"><xsl:value-of select="@hostname"/></td>
<td Class="Cell1"><xsl:value-of select="@update"/></td>
<td Class="Cell1"><xsl:value-of select="hardware/case"/></td>
<td Class="Cell2"><xsl:for-each select="hardware/cpu/name"><xsl:value-of select="."/> (@ <xsl:value-of select="@speed"/> MHz)<br/></xsl:for-each></td>
<td Class="Cell1"><xsl:for-each select="hardware/harddisc/name"><xsl:value-of select="."/> (Size: <xsl:value-of select="@size"/> GB)<br/></xsl:for-each></td>
<td Class="Cell2"><xsl:value-of select="hardware/ram"/> (Typ: <xsl:value-of select="hardware/ram/@type"/>)</td>
<td Class="Cell1"><xsl:for-each select="hardware/drives/name"><xsl:value-of select="."/> (Typ: <xsl:value-of select="@type"/>)<br/></xsl:for-each></td>
<td Class="Cell2"><xsl:value-of select="hardware/monitor"/></td>
<td Class="Cell1"><xsl:value-of select="hardware/printer"/></td>
<td Class="Cell2"><xsl:value-of select="hardware/scanner"/></td>
<td Class="Cell1"><xsl:for-each select="hardware/etc/name"><xsl:value-of select="."/><br/></xsl:for-each></td>
<td Class="Cell1"><xsl:value-of select="software/os"/></td>
<td Class="Cell2"><xsl:for-each select="software/application/name"><xsl:value-of select="."/><br/></xsl:for-each></td>
</tr>
</table>
<br/><br/>
</xsl:for-each>
</xsl:if>
<xsl:if test="$search = ''">
<xsl:for-each select="database/computer">
<table border="0" cellpadding="4" width="100%">
<tr>
<td Class="AreaHeader1" colspan="3">Information about Computer:</td>
<td Class="AreaHeader2" colspan="9">Hardware:</td>
<td Class="AreaHeader3" colspan="2">Software:</td>
</tr>
<tr>
<td Class="HeaderCell1">Owner and Computer ID</td>
<td Class="HeaderCell2">Hostname</td>
<td Class="HeaderCell1">Dataset last updated:</td>
<td class="HeaderCell3">Case</td>
<td class="HeaderCell4">CPU(s)</td>
<td class="HeaderCell3">Harddisc(s)</td>
<td class="HeaderCell4">RAM</td>
<td class="HeaderCell3">Drive(s)</td>
<td class="HeaderCell4">Monitor</td>
<td class="HeaderCell3">Printer</td>
<td class="HeaderCell4">Scanner</td>
<td class="HeaderCell3">etc</td>
<td Class="HeaderCell5">OS</td>
<td Class="HeaderCell6">Application(s)</td>
</tr>
<tr>
<td Class="Cell1"><xsl:value-of select="@owner"/> (<xsl:value-of select="@id"/>)</td>
<td Class="Cell2"><xsl:value-of select="@hostname"/></td>
<td Class="Cell1"><xsl:value-of select="@update"/></td>
<td Class="Cell1"><xsl:value-of select="hardware/case"/></td>
<td Class="Cell2"><xsl:for-each select="hardware/cpu/name"><xsl:value-of select="."/> (@ <xsl:value-of select="@speed"/> MHz)<br/></xsl:for-each></td>
<td Class="Cell1"><xsl:for-each select="hardware/harddisc/name"><xsl:value-of select="."/> (Size: <xsl:value-of select="@size"/> GB)<br/></xsl:for-each></td>
<td Class="Cell2"><xsl:value-of select="hardware/ram"/> (Typ: <xsl:value-of select="hardware/ram/@type"/>)</td>
<td Class="Cell1"><xsl:for-each select="hardware/drives/name"><xsl:value-of select="."/> (Typ: <xsl:value-of select="@type"/>)<br/></xsl:for-each></td>
<td Class="Cell2"><xsl:value-of select="hardware/monitor"/></td>
<td Class="Cell1"><xsl:value-of select="hardware/printer"/></td>
<td Class="Cell2"><xsl:value-of select="hardware/scanner"/></td>
<td Class="Cell1"><xsl:for-each select="hardware/etc/name"><xsl:value-of select="."/><br/></xsl:for-each></td>
<td Class="Cell1"><xsl:value-of select="software/os"/></td>
<td Class="Cell2"><xsl:for-each select="software/application/name"><xsl:value-of select="."/><br/></xsl:for-each></td>
</tr>
</table>
<br/><br/>
</xsl:for-each>
</xsl:if>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
well now - THIS is the php used to convert the xml using xsl to xhtml on the server: PHP Code:
edit: disabled smilies Last edited by zyrill : June 2nd, 2003 at 09:32 AM. |
|
#2
|
|||
|
|||
|
sorry for the mess with the code... and thanks a million... ano more thing though: how would i sort the tables by owner, cpuname or somthing like that when using "xsl:call-template" (which btw works like a charm... *sigh*)
|
|
#3
|
|||
|
|||
|
i seem to be too stupid to get it to work this time - i tried both
"<xsl:sort select="/database/computer/@id" data-type="number" order="descending"/>" and "<xsl:sort select="@id" data-type="number" order="descending"/>" but neither would work - it just doesn't affect the output whatsoever - nothing happens - it's just as if the xsl:sort was non-existent. this is one whole block of the xsl:when statements i have written - i think it's correct since everything works and displays fine just the sorting doesn't seem to kick in! Code:
<xsl:when test="$search='@owner'"> <xsl:for-each select="/database/computer[@owner=$searchparam]"> <xsl:sort select="@id" data-type="number" order="descending"/> <xsl:call-template name="createset"/> </xsl:for-each> </xsl:when> |
|
#4
|
|||
|
|||
|
forget it - it works... i've been too stupid to notice...
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL evaluating variables doesn't work correctly (as i wish it to ;)) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|