Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS is not being rendered in XML document 1

Status
Not open for further replies.

kashka

Technical User
Nov 3, 2002
6
JM
Could you please help me out? I have the following xml document that uses CSS to display information in a particular display format. What happens when I views it, it just displays the text normally but no rendering. Could you please let me know if I am doing something wrong? Here is the code:

<?xml-stylesheet type="text/css" href="#internalstyles" ?>
<document>
<style id="internalstyles">
annotation {border:solid 3px green; font-size:12pt;
display:block;border-left:none;border-right:none;
font-family:Arial}

para {font-size:11pt;display:block;}
style{display:none;}
</style>
<para>The rain spat against the apartment's window pane,
torrential for this part of Los Angeles, though Gina would
not have much noticed it at home. The rain straddled the
boundary between the life blessing touch that this
valley so seldom received and the caustic depressed
state that lately so made up her soul. </para>
<para>"Rain, Rain, Go Away," she sang listlessly, though as
she doodled over the script that Stan had sent, Gina secretly
relished the rain, as indulgent as the black mood she wore
around herself.</para>
<annotation>
<para>Rain is a metaphor throughout this story as an expression
of both elemental force and chaotic emotions.</para>
</annotation>
<para>She didn't want to do the script, not really - the
scripts that she received anymore were hardly star makers,
though her star had risen fairly high once, only to be knocked
off course by the ... ah, what was the term the publicist had
used ... the incident, that was it. </para>
</document>
 
Don't put your content in the stylesheet. Create an XML file for the content and reference the stylesheet file.
 
Well I was following the exercise in a Wrox book called "Beginning XML" and they had the content and the stylesheet in one document and it works for them but I guess that's not the case with me. By the way, are you familiar with XSL? If so, what does "No prefix for "xsl"" mean?
 
...it works for them...
That's a big leap of faith when you're dealing with a Wrox book, unfortunately. I have an earlier edition of that book. That example has been changed, obviously because there were many errors in it. Apparently the changes weren't sufficient. I'd either look for errata on the Wrox site or just skip it: it's not that important.

I can't answer your XSL question out of context: what processor are you using, what does the input look like... Give me something to try to duplicate the error.
 
I am using a Pentium M Processor with Centrino @ 1.3GHz
Here is the xsl file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns="<xsl:eek:utput method="xml" indent="yes"/>

<xsl:template match="/">
<order>
<date>
<xsl:value-of select="/order/date/year"/>/<xsl:value-of
select="/order/date/month"/>/<xsl:value-of select="/order/date/day"/>
</date>
<customer>Company A</customer>
<item>
<xsl:apply-templates select="/order/item"/>
<quantity><xsl:value-of select="/order/quantity"/></quantity>
</item>
</order>
</xsl:template>

<xsl:template match="item">
<part-number>
<xsl:choose>
<xsl:when test=". = 'Production-Class Widget'">E16-25A</xsl:when>
<xsl:when test=". = 'Economy-Class Widget'">E16-25B</xsl:when>
<!--other part-numbers would go here-->
<xsl:eek:therwise>00</xsl:eek:therwise>
</xsl:choose>
</part-number>
<description><xsl:value-of select="."/></description>
</xsl:template>
</xsl:stylesheet>

============================================================

Here is the xml file:

<?xml version="1.0" ?>
<order>
<salesperson>John Doe</salesperson>
<item>Production-Class Wwidget</item>
<quantity>16</quantity>
<date>
<month>1</month>
<day>13</day>
<year>2000</year>
</date>
<customer>Sally Finkelstein</customer>
</order>
 
When I said, "what processor," I meant "what XSLT processor," not which CPU. Nevermind, though, I figured it must be xt because of the book.

Anyway, in the second line of your XSL file where you have
Code:
xmlns=
it should be
Code:
xmlns:xsl=

A simple typo/syntax error.
 
I'm so embarrassed. I'm new to this so bare with me. Thanks I will try it and let you know how it goes.
 
It works! It was a typo. What books do you recommend I read to learn this sort of thing?
 
Recommendations

1: Keep two files with XML, XSL declarations handy so you can cut and paste. It eliminates this maddening type of error.

2. Aside from the mistakes in the code, Hunter's book isn't bad. But I've come to hate Wrox for rushing books to press without making sure the code is correct. (The only exception to the "Wrox Rule" are Rocky Lhotka's books, which cover VB.) Avoid the Deitel et al. book, "XML How to Program" from Prentice Hall(!) It's as error-filled as any Wrox book, and the host of authors makes for extremely uneven coverage of the important topics. It's also arrogantly pedantic and dense; only a PhD could love this baby.

3. Alternative to a book, the "Partners" panel (left column here) has some good places on the Web to go for XML tutorials, like zvon.

4. Once you have a feel for XML, get Elliotte Rusty Harold's book, "Effective XML." This imparts a depth of understanding that I don't find anywhere else, and it's easy to read.

5. When you need to go deeper into XSLT than Hunter takes you, get Jeni Tennison's "Beginning XSLT." APress is the new publisher. (Wrox was the former publisher, and come to think of it, this book was also relatively error-free. Well, if I have to admit that, here's my "Wrox Rule Corollary:" Publish lots of expensive technical books, do it in a rush to cash in, make lots of aggravating errors, p*ss-off the readers, go bankrupt. Lousy business model.)

Good luck, and come back anytime, as there are many people to answer questions.

(I've recommended all this here before, but I can't find it now. I probably ought to write it up as something other than a post in a thread.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top