[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem to make Xtemplate parse my XHTML

simonced

6/15/2005 5:11:00 AM

hi everyone,

I ecounter a problem for few days.
I don't manage to axpand something like this :

template>>>
<tr id="acteurs" class="acteurs">
<td id="td"><a id="a"/></td>
<td id="descrip"/>
<td id="valeur"/>
<td id="repetition"/>
</tr>
<<<template

ruby code >>>
....
data=Hash.new
data['acteurs']=Array.new
#on fait la liste des acteurs
liste = $_my.query("SELECT * FROM acteur")

i=0
while(result=liste.fetch_hash)
#couleur une ligne sur 2
result['@bgcolor']='#DDDDDD' if(i%2==0)

result['td']=[{"a"=>result['nom'], "@href"=>"toto.php"}]

data['acteurs'].push(result)
i+=1
end

#---------------------
center=template.expand(data)
....
<<<ruby code

The problem is that the href attribute is in the td tag, not in a !
I really looked everywhere in tutorial on xtemplate, and nothing really
helped me.
So, if someone help me out, it would help me very much.

Thanks.

simonced.

8 Answers

Takaaki Tateishi

6/15/2005 2:45:00 PM

0

simonced wrote:
> result['td']=[{"a"=>result['nom'], "@href"=>"toto.php"}]

The above line should be as follows.

result['td'] = {"a" => {XTemplate::TextNode => result['nom'],
"@href" => "toto.php"}}
--
Takaaki Tateishi <ttate@ttsky.net>



simonced

6/15/2005 7:39:00 PM

0

Thank you very much !
I didn't understant nothing about it in the documentation.
Is there a good place to get infos about Xtemplate ? The original
website is quite poor about it I think.

Moreover, I have another question.
In the tut, they say I can copy a "part" of one template and past it in
another one. Their exemple works, but not in may app.

main>>>
<html xmlns:xt="#{XTemplate::BIND_URI}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<!--Titre-->
<tr>
<td colspan="2" align="center">
<h3>Gestion de budget - Simulation mensuelle</h3>
</td>
</tr>
<tr>
<!--Navigation-->
<td class="navigation" valign="top">
nav
</td>

<td align="left" valign="top">
<div class="centre">
<xt:template name="include">
toto
</xt:template>
</div>
</td>
</tr>
</table>
</body>
</html>
<<<

template>>>
<html xmlns:xt="#{XTemplate::BIND_URI}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!--TAble de liste-->
<xt:template name="include">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15%"><b>Nom</b></td>
<td width="35%"><b>Description</b></td>
<td width="25%"><b>Montant</b></td>
<td><b>R&eacute;p&eacute;tition</b></td>
</tr>
<!--Liste des acteurs-->
<tr id="acteurs" class="acteurs">
<td id="td"><a id="a"/></td>
<td id="descrip"/>
<td id="valeur"/>
<td id="repetition"/>
</tr>
</table>
</xt:template>
</body>
</html>
<<<

here is the ruby code :
[...]
$_main["include"]=template["include"]
$_main.expand(data)

Sorry, I put all my htm code, but I wasn't sure wich part I could
remove.
Thanks by advance.

simonced

Takaaki Tateishi

6/15/2005 9:15:00 PM

0

simonced wrote:
> Is there a good place to get infos about Xtemplate ? The original
> website is quite poor about it I think.

Maybe documentations of Amrita are useful for you, since an expansion
argorithm of xtemplate is almost same as one of Amrita.

> Moreover, I have another question.
> In the tut, they say I can copy a "part" of one template and past it in
> another one. Their exemple works, but not in may app.
...
> <tr id="acteurs" class="acteurs">
> <td id="td"><a id="a"/></td>
> <td id="descrip"/>
> <td id="valeur"/>
> <td id="repetition"/>

You must use 'xt:id' instead of 'id', onece you declare the namespace 'xt'.

Regards,
--
Takaaki Tateishi <ttate@ttsky.net>



simonced

6/16/2005 5:01:00 AM

0

I'll look better to Amrita documentation.

but, When I runmy script, I have a blank page.
So, to chek errors, I ran my script by a shell.
And I saw this error :
/usr/lib/ruby/site_ruby/1.8/xtemplate.rb:53:in `[]=': undefined method
`children=' for nil:NilClass (NoMethodError)
from index.rb:33
Is it a bug from Xtemplate ?
My code who does it is :
$_main["include"]=template["include"]
How does it work ?

Thanks very much by Advance.
Simonced.

Takaaki Tateishi

6/16/2005 3:35:00 PM

0

simonced wrote:
> And I saw this error :
> /usr/lib/ruby/site_ruby/1.8/xtemplate.rb:53:in `[]=': undefined method
> `children=' for nil:NilClass (NoMethodError)
...
> $_main["include"]=template["include"]
> How does it work ?

template["include"] returns sub-template named by <xt:template name="...">, and
a sub-template "include" of $_main is replaced with it. Please check both of
$_main["include"] and template["include"].
Also, the following program work on my environment.

Thanks,

require 'xtemplate'
$_main = XTemplate::XMLTemplate.new(<<EOS)
<html xmlns:xt="#{XTemplate::BIND_URI}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<!--Titre-->
<tr>
<td colspan="2" align="center">
<h3>Gestion de budget - Simulation mensuelle</h3>
</td>
</tr>
<tr>
<!--Navigation-->
<td class="navigation" valign="top">
nav
</td>

<td align="left" valign="top">
<div class="centre">
<xt:template name="include">
toto
</xt:template>
</div>
</td>
</tr>
</table>
</body>
</html>
EOS

template = XTemplate::XMLTemplate.new(<<EOS)
<html xmlns:xt="#{XTemplate::BIND_URI}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<link href="../styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!--TAble de liste-->
<xt:template name="include">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15%"><b>Nom</b></td>
<td width="35%"><b>Description</b></td>
<td width="25%"><b>Montant</b></td>
<td><b>R&eacute;p&eacute;tition</b></td>
</tr>
<!--Liste des acteurs-->
<tr xt:id="acteurs" class="acteurs">
<td xt:id="td"><a id="a"/></td>
<td xt:id="descrip"/>
<td xt:id="valeur"/>
<td xt:id="repetition"/>
</tr>
</table>
</xt:template>
</body>
</html>
EOS

data = {'acteurs' => [
{'td' => 'TD', 'descrip'=>'d1', 'valeur'=>'v1', 'repetition'=>'r1'},
]}
$_main["include"]=template["include"]
puts $_main.expand(data)

--
Takaaki Tateishi <ttate@ttsky.net>



simonced

6/16/2005 8:36:00 PM

0

Yes, thanks, I see it's wroking.
I have to find where I did a mistake.
I have my child script that calls a main script.
The main create $_main var.
Maybe when the script goes back in child script, $_main is not fully
fonctionnal.
I don't know.
I'll investigate for it.
Moreover, my templates are is separate xhtml files, could it change
something ? I don't think so, but I have so weird results...

I'll give news about my investigations about it.
Thanks

Simonced.

simonced

6/18/2005 7:23:00 AM

0

I discovered a strange problem !
Did anybody sever swa that ?!
When I load my Template with a string from within the code, it's
working !
ex :
template=Xtemplate::XMLTemplate.new(<<EOS)
[...content of the XHTML template here...]
EOS

But, if my template is in a separated file it's not working, I load it
like this :
template = Xtemplate::XMLTemplate.new(IO.read("../acteurs/acteurs.htm")

Does somene know where there is a problem ?
Thank by advance

Simonced.

simonced

6/20/2005 5:03:00 AM

0

Does anyone knoes why
template =
Xtemplate::XMLTemplate.new(IO.read("../acteurs/acteurs.htm")
doesn't work at all ?
IO.read has special properties ?

Thx for help

simonced