Topic: My XML assignment (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=11057" title="Pages that link to Topic: My XML assignment (Page 1 of 1)" rel="nofollow" >Topic: My XML assignment <span class="small">(Page 1 of 1)</span>\

 
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 09-24-2003 02:01

I have to build small web site ( 3 pages) using XML and XSL.
Well, honestlly I am pretty confused about this XML things.
I cannot describe details about what I am confused but I want to say something.

1. Am I allowed to put CSS stylesheet link in XSL file?
XSLT is stylesheet of XML, right. That is fine. I am making a template to show XML data as XHTML. My XSL file is including table. I wanted to formate it nicely. My code was like:

code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">
<html>
<body style="font-family: verdana; font-size: x-small;">
<h3>Ophihi Vinyeard Home Page</h3>

<table style="font-size: x-small; border: solid 1px #000;border-collapse: collapse; ">
<tr bgcolor="#9acd32">
<th style="border: solid 1px #000;padding: 5px;">Wine</th>
<th style="border: solid 1px #000;padding: 5px;">Color</th>
<th style="border: solid 1px #000;padding: 5px;">Award</th>
<th style="border: solid 1px #000;padding: 5px;">Price</th>
</tr>

<xsl:for-each select="home/list">
<tr >

<td style="border: solid 1px #000;padding: 5px;"><xsl:value-of select="wine" /></td>
<td style="border: solid 1px #000;padding: 5px;"><xsl:value-of select="color" /></td>
<td style="border: solid 1px #000;padding: 5px;"><xsl:value-of select="award" /></td>
<td style="border: solid 1px #000;padding: 5px;"><xsl:value-of select="price" /></td>

</tr>
</xsl:for-each>

</table>

</body>
</html>

</xsl:template>

</xsl:stylesheet>



Then I thought it is pretty much like INLINE format, which is not convinient to change formate many pages at once. I tried to put CSS inside of XSLT file like:

code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">


<xsl:template match="/">
<html>
<head>
[b]<link rel="stylesheet" type="text/css" href="1-1.css" />[/b]
</head>
<body style="font-family: verdana; font-size: x-small;">
<h3>Ophihi Vinyeard Home Page</h3>

<table style="font-size: x-small; border: solid 1px #000;border-collapse: collapse; ">
<tr bgcolor="#9acd32">
<th >Wine</th>
<th >Color</th>
<th >Award</th>
<th >Price</th>
</tr>

<xsl:for-each select="home/list">
<tr >

<td ><xsl:value-of select="wine" /></td>
<td ><xsl:value-of select="color" /></td>
<td ><xsl:value-of select="award" /></td>
<td ><xsl:value-of select="price" /></td>

</tr>
</xsl:for-each>

</table>

</body>
</html>

</xsl:template>

</xsl:stylesheet>



Well, it worked fine (IE5.0). What I have done is: take out all td and th stlyle then put them into stylesheet file called 1-1.css. Then made a link in head section of XSL file. Hmm.........

Well, let me clear again.
1. I cannot see the point making web site using XML and XSLT. Is that any good thing behind them?
2. I cannot see the point to apply XSLT to XML to display data. Why not just apply CSS on XML???

Well, I have to do it even though I am pretty confused.......Ah........

Hiroki Kozai

[This message has been edited by Hiroki (edited 09-24-2003).]

[This message has been edited by Hiroki (edited 09-24-2003).]

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 09-24-2003 03:43

Hiroki: As you already know, the goal of XSLT is to transform XML datas into ... something else i.e. XHTML, HTML, CSV, PLAIN TEXT, etc...
So far, I've only used the XML + XSLT + CSS combo in heavy Content Management Systems where every little part of a site can be administrated and skinned. But it can be used for smaller web sites that generate or retrieve XML feeds.

AFAIK, it's impossible to directly link a CSS to some XML datas.
BTW, modern browsers like MZ and IE6 can directly read XML feeds so you no longer need to point to a server side script to handle the XML datas with them. I don't know if that's already what you did, but alazanto brillantly illustrates this point.

Hope that helps a little.

Mathieu "POÏ" HENRI

[This message has been edited by poi (edited 09-24-2003).]

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 09-26-2003 08:38

Hi, mate.
Many thanks for your reply.
Can I ask more?
Do you know how to show the picuture using XML and XSLT?
In my XML file,
<pic>1.jpg</pic>
something like that. There are so many picutures in my mind. In my XSLT,

code:
<xsl:for-each select="home/list"><tr >
<td ><xsl:value-of select="pic" /></td>
</tr></xsl:for-each>



But all I saw is just that file name: 1.jpg. I wanna show the picutre instead of it.
Do you know how to do this kind of things???


Hiroki Kozai

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 09-26-2003 11:07

Hiroki: No problem. I've had a lot of trouble with XSL back in time, and still have a bad feeling about this language . To generate an IMG tag, infact, you have to feed the src attribute of an IMG tag. And don't forget that XSL behaves like XHTML and requires that you close *every* tags. That's why you write <br />,<hr /> or <img />.
Now for the example:

code:
<img border="2">
<xsl:attribute name="src"><xsl:value-of select="pic" /></xsl:attribute>
</img>

I've set the border directly to make sure you don't forget that you can mix "direct" attributes and xsl attributes.
Another important point is that once the opening tag is over, you can still add some complex attributes like style with: <xsl:attribute name="style">background-color:green;<xsl:attribute name="border">8px <xsl:value-of select="border_style" /></xsl:attribute>;</xsl:attribute>.

Well you see, if you hadn't already, that the syntax of XSL can quickly become a nightmare.
Hope that helps.

Mathieu "POÏ" HENRI
[edit]fixed a in :g[/edit]

[This message has been edited by poi (edited 09-27-2003).]

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 09-27-2003 07:01

Hi, Poi. Many thanks for your reply.
That is great!
Make sense to me.
I have't tried yet.
Pretty soon, I will go through it!
cheers,mate.



Hiroki Kozai

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 09-27-2003 07:07

Oh, great!
It is working~!!!
Great!!!!
Ahaaa........
Thanks.

Hiroki Kozai

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 09-27-2003 16:39

To arguee my "bad feeling" about XSL, here are the main points that annoy me:

  • the heavy syntax
  • the poor support of variables. You can't alter the variables, and if you want to make a kind of for loop, you'll have to make a recursive function.
  • the trickyness to put a simple &nbsp; or any common entity. For this you have to use the Latin-1 Entities. &#160; for the current case. Ok, it's normal but what a hell for a simple non-breaking space.
  • the rather fuzzy way to handle new line feeds and cariage returns. It can be critical when you have to generate a CSV.

Notice that my "critics" comes from my experience of XSLT via SABLOTRON.

Mathieu "POÏ" HENRI

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 09-29-2003 05:51

Hi, mate. Thanks for your help!
I wanna ask further if you don't mind.
Well, In my xml database, there are wine list. Some wine gets award.
I am trying to suck only wine which gets award. Here is my code of XSL.

code:
<xsl:for-each select="home/list">
<xsl:choose>
<xsl:when test="award &#61; Gold and award &#61; Silver and award &#61; Bronze">

<tr >

<td ><xsl:value-of select="winery" /></td>
<td ><xsl:value-of select="wine" /></td>
<td ><xsl:value-of select="color" /></td>
<td ><xsl:value-of select="award" /></td>
<td ><xsl:value-of select="price" /></td>

</tr>
</xsl: when>
</xsl:choose>
</xsl:for-each>



As you know, it doesn't work at all. I have tested using IE6. And I guess this line:

<xsl:when test="award &#61; Gold and award &#61; Silver and award &#61; Bronze">

Is it wrong??? I cannot see why it does not work. When I open my XML file using IE6, it is only showing table heading not data at all. Help!

Hiroki Kozai

Nathus
Nervous Wreck (II) Inmate

From: Minnesota
Insane since: Aug 2003

posted posted 09-29-2003 08:11

First of all, if you only want to print it out if it meets a certain criteria, and do nothing if it doesn't meet that criteria, you should use xsl:if

Secondly, you would use 'or', not 'and' as an operator, otherwise you would be looking for cases where it was awarded all 3 awards.

code:
<xsl:for-each select="home/list">
<xsl:if test="award = 'Gold' or award = 'Silver' or award = 'Bronze'">
<tr >

<td ><xsl:value-of select="winery" /></td>
<td ><xsl:value-of select="wine" /></td>
<td ><xsl:value-of select="color" /></td>
<td ><xsl:value-of select="award" /></td>
<td ><xsl:value-of select="price" /></td>

</tr>
</xsl:if>
</xsl:for-each>



poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 09-29-2003 16:35

Hiroki: Your troubles came more from a problem of logic ( and the lack of quotation marks ) rather than XSL. Indeed if you had read, litterally, your statetement, you would have found out that the award field can never be 'Gold' _and_ 'Silver' _and_ 'Bronze' but only one of these value at a time.

Nonetheless, Nathus is right to advise you to use <xsl:if ... > which is more appropriate for your test. I'll add that the <xsl:choose><xsl:when ...>...</xsl:when ...><xsl therwise:>...</xsl therwise:></xsl:choose> statement is the XSL equivalent of the switch( ... ){ case ...: break; default: ... } statement in other languages.

Mathieu "POÏ" HENRI
[edit]disabling Slimies[/edit]

[This message has been edited by poi (edited 09-29-2003).]

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 09-30-2003 07:13

Hi, mates. Many thanks for your help.
Now I am at web firm to get some work experience.
Well, excited!

Hiroki Kozai



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu