SunQuest
           XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old June 2nd, 2003, 08:06 AM
zyrill zyrill is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 4 zyrill User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question XSL evaluating variables doesn't work correctly (as i wish it to ;))

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:
<?php
if ($_POST["submit"])
{
  if (isset(
$_POST["search"]))
  {
      
$search $_POST["search"];
  }
  else
  {
      
$search 'nil';
  }
  if ((isset(
$_POST["searchparam"])) and ($_POST["searchparam"] != ''))
  { 
      
$searchparam $_POST["searchparam"];
  }
  else
  {
      
$searchparam 'nil';
  }
  if (isset(
$_POST["sort"]))
  {
      
$sort $_POST["sort"];
  }
  else
  {
      
$sort 'nil';
  }
}

$xmlfile 'computers.xml';
$xslfile 'sort.xsl';

$xh xslt_create();
$arguments = array ( 'foo' => 'bar' );
$parameters = array (
    
'search' => $search,
    
'searchparam' => $searchparam,
    
'sort' => $sort );
$result xslt_process($xh$xmlfile$xslfileNULL$arguments$parameters);
if (
$result) {
    print 
$result;
}
else {
    print 
"Either <font color='#0000FF'>$xmlfile</font> or <font color='#0000FF'>$xslfile</font> seems to be erratic.";
    print 
"<br>Following error occured while trying to perform the tranformation: <font color='#FF0000'>" xslt_error($xh) . 
    print 
"</font><br>The error code is <font color='#FF0000'>" xslt_errno($xh) . "</font>";
}
xslt_free($xh);
?>


edit: disabled smilies

Last edited by zyrill : June 2nd, 2003 at 09:32 AM.

Reply With Quote
  #2  
Old June 2nd, 2003, 09:14 AM
zyrill zyrill is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 4 zyrill User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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*)

Reply With Quote
  #3  
Old June 2nd, 2003, 09:56 AM
zyrill zyrill is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 4 zyrill User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #4  
Old June 2nd, 2003, 10:01 AM
zyrill zyrill is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 4 zyrill User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
forget it - it works... i've been too stupid to notice...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL evaluating variables doesn't work correctly (as i wish it to ;))


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway