|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
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
|
|||
|
|||
|
I can't seem to make my underline (or bold) style work in an ordered or unordered list.
This is in the XSL Stylesheet: <xsl:template match="utxt"> <u> <xsl:apply-templates /> </u> </xsl:template> And this is the xml document: <alphalist> <item><utxt>I want this underlined</utxt> - But it won't do it. I really wish it would.</item> </alphalist> I have also tried this in the XSL stylesheet with no success: <xsl:template match="utxt"> <span style="text-decoration:underline"> <xsl:apply-templates /> </span> </xsl:template> I'm going nuts. Please help. |
|
#2
|
|||
|
|||
|
Hello annadeus. I put your code into an xml and xsl files, and both worked fine. Perhaps there is something wrong with the link between the XML and the XSL? I'll include the example files I created.
u.xml Code:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="u.xsl" ?>
<alphalist>
<item>
<utxt>I want this underlined</utxt>
- But it won't do it. I really wish it would.
</item>
</alphalist>
u.xsl Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="utxt">
<u>
<xsl:apply-templates />
</u>
</xsl:template>
</xsl:stylesheet>
If you want to post the actual files I'll take a look at them. |
|
#3
|
|||
|
|||
|
Hmmm...still doesn't work here.
Here are the relevant parts of my files: test.xsl - -------------------------------------------------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <style> ol {margin-top:0px; margin-bottom:10px} li {margin-top:4px; font-weight:normal} </style> </head> <body> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="section"> <div style="margin:0px 18px 12px 12px"> <xsl:apply-templates /> </div> </xsl:template> <xsl:template match="underline"> <u> <xsl:apply-templates /> </u> </xsl:template> <xsl:template match="alphalist"> <ol type="a"> <xsl:apply-templates select="./*"/> </ol> </xsl:template> <xsl:template match="item"> <li> <xsl:value-of select="."/> </li> </xsl:template> </xsl:stylesheet> -------------------------------------------------------------- test.xml - -------------------------------------------------------------- <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="test.xsl" ?> <!DOCTYPE topic SYSTEM "test.dtd"> <topic> <section> <alphalist> <item> <underline>I want this underlined</underline> - But it won't do it. I really wish it would. </item> <item> <underline>I want this underlined</underline> - Still nothing. </item> </alphalist> </section> </topic> -------------------------------------------------------------- Is there any special way I need to treat <underline> in the DTD? Sorry, I'm new and dumb at this forum and don't know how to post my code all nice-like as you did! Last edited by annadeus : November 26th, 2003 at 10:27 AM. |
|
#4
|
|||
|
|||
|
Hello again annadeus. Just a note, if your document doesn't exactly match up to what you have defined in your DTD, nothing will work. The underlining shouldn't have anything to do with the DTD - that should be done in the XSL document. I didn't have your DTD, so I don't know if it's correct, but after some tinkering I got your XSL to work. You will know if your DTD and your XML file match up by opening your XML file in IE - you will get an error if it is incorrect.
Ok, so using the same xml document you posted (minus the DTD reference, I rewrote your XSL to this: (Oh and by the way, to get the code to show up "all cool", put "["code"]" and "["/code"]", minus the quotation marks, on both ends of your code.) Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--I changed the formatting on this a bit, just because
this is what I am used to, and for what you're doing
here it really cuts down on the code.
Remember that periods select all the content that
hasn't already been grabbed... I think that is
probably where your problems were coming in. -->
<xsl:template match="/">
<html>
<head>
<style>
ol {margin-top:0px; margin-bottom:10px}
li {margin-top:4px; font-weight:normal}
</style>
</head>
<body>
<div style="margin:0px 18px 12px 12px">
<ol type="a">
<xsl:for-each select="/topic/section/alphalist/item">
<li>
<!--Grab the underlined text and then
add all the rest of the content for
item (using the .) -->
<u><xsl:value-of select="underline" /></u>
<xsl:value-of select="." />
</li>
</xsl:for-each>
</ol>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I use the site W3 Schools when I'm trying to do anything with XML. You should check it out - it's very helpful. |
|
#5
|
|||
|
|||
|
I had to tweak your tweak to fit into my grand scheme of things, and the funny thing was that the underlined text would appear twice in a row.
I did, fortunately, manage to figure it out through mulitple incarnations of XSL file tinkering. It ended up being stupid, really. I had this: Code:
<xsl:template match="item">
<li>
<xsl:value-of select="."/>
</li>
</xsl:template>
...when I should have had this: Code:
<xsl:template match="item">
<li>
<xsl:apply-templates />
</li>
</xsl:template>
Thanks a ton for your help, tsprings. I'm just starting to learn this stuff. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > style not working in lists |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|