|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
The XSL I have made is based mainly on div tags with style attributes. Here's the XML document. It won't render "Links" under <SIDE></SIDE>.The gibberish in the <POST></POST> tag is to test the word-wrapping.
Code:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="Underscore.xsl"?> <PAGE> <TOP>Underscore</TOP> <SIDE><a href="http://www.geocities.com">Links</a></SIDE> <POST>OOPGRJEGHJKLJIWSIFDPSIOGGGGGGIKKKKKKKKFFFFFFFGGGGGROEJGGFLSJGLKFDJSKLJFLDSJLFJDLSJGRIOVJFSPOIFODSKGO RRRRSGFSHJKGHREKVJNDFSLUTIRISLNGILRMSINGSFLDNFIIIIDUSIGNURIOWSGPROSPUGIERUIOPWSNGUIEUSIUGIDSNJFIWSJD HSSOGNRUOSIUUGGUIEORDSOYUEWUOQQORIUSUAIFUYHEHWUSHVF</POST> </PAGE> Here's the XSL stylesheet. Code:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="br"> <br/> <xsl:apply-templates/> </xsl:template> <xsl:template match="PAGE"> <html> <body style="margin:0px;"> <children/> </body> <xsl:apply-templates/> </html> </xsl:template> <xsl:template match="SIDE"> <div style="background-color:00BBFF;width:20%;height:100%;float:right"><div style="margin-top:10px;font-size:30px"><child/></div></div> <xsl:apply-templates/> </xsl:template> <xsl:template match="POST"> <div style="margin-left:10px;margin-right:10px;word-wrap:break-word"> <P> <children/><xsl:apply-templates/> </P> </div> </xsl:template> <xsl:template match="TOP"> <div style="background-color:00BBFF;width:100%;height:20%;text-align:center;font-size:60px;font-family:anythingyouwant;color:0066BB"> <div style="margin-top:10px"><children/></div> <xsl:apply-templates/> </div> </xsl:template> </xsl:stylesheet> Any help will be appreciated. Thanks. |
|
#2
|
|||
|
|||
|
Try the following (I removed the styling code for clarify):
Code:
<xsl:template match="SIDE">
<xsl:copy-of select="./a"/>
</xsl:template>
|
|
#3
|
||||
|
||||
|
That code didn't work? Not for me at least. When I did that, it made Links copy, turn blue and hyperlink to geocities.com.... Wonder what i'm doing wrong.
|
|
#4
|
||||
|
||||
|
Quote:
I am confused ... isn't this what you want it to do? What do you mean by "It won't render links under <SIDE></SIDE>?" |
|
#5
|
|||
|
|||
|
Hi AdorablePuppy.
I suggest you take a look at W3 Schools for more info on xsl. I reformatted your whole XSL document (using the code posted by fpmurphy), which included links to the right (right where you specified in the style for that div). This does link to google, because that's what address you had specified in your xml doc. Links was showing up an extra time because of some incorrect xsl, but that should be cleaned up now and closer to what you are looking for. Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body style="margin:0px;">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="SIDE">
<div style="background-color:00BBFF;width:20%;height:100%;float:right">
<div style="margin-top:10px;font-size:30px">
<xsl:copy-of select="./a"/>
</div>
</div>
</xsl:template>
<xsl:template match="POST">
<div style="margin-left:10px;margin-right:10px;word-wrap:break-word">
<P><xsl:apply-templates/></P>
</div>
</xsl:template>
<xsl:template match="TOP">
<div style="background-color:00BBFF;width:100%;height:20%;text-align:center;font-size:60px;font-family:anythingyouwant;color:0066BB">
<div style="margin-top:10px"></div>
<xsl:apply-templates/>
</div>
</xsl:template>
</xsl:stylesheet>
|
|
#6
|
||||
|
||||
|
Well....
Could you show me what was incorrect? I want to learn from this experience.
I've read through the W3's XML and XSL specifications. I've referenced several XSL documents... I've read through the latest edition of the XML Handbook. But none of these things acutally HELPED me with XSL because I didn't understand how it worked by reading it. I have to understand it through experiencing my problems... That's why I need to learn from my mistake by you posting the incorrect XSL. Thank you... Last edited by adorablepuppy : April 1st, 2004 at 04:48 PM. |
|
#7
|
||||
|
||||
|
Quote:
That is why I recommended that you look up W3 Schools, because W3 Schools is very clear and easy to understand... A great resource for learning XSL. I am a kinesthetic learner as well, and W3 Schools provides some great examples. Quote:
I'm not sure what you mean by me posting the incorrect XSL, as you can compare an contrast your XSL and the XSL I provided and see where they differ... Nonetheless, I have included another XSL that is well commented and includes your code that I changed, as well as explanations as to why I changed what I did. Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--Why are you making a separate template that inserts a <br />? Why not just insert it where
you need it in your XSL? I would strongly suggest removing this.
<xsl:template match="br">
<br/>
<xsl:apply-templates/>
</xsl:template>-->
<!--Ok, so here you're matching your root element. That's fine. For ease
of use, I'd put my rood-matching template first thing in the xsl file.-->
<xsl:template match="PAGE">
<html>
<!--So you declare the body tags for the html, that is fine, but then
you declare 'children'. I'm not exactly sure what you are trying
to accomplish with this, and I'd remove it. I'd also place the
xsl:apply-templates inside the body tags.
<body style="margin:0px;">
<children/>
</body>
<xsl:apply-templates/>-->
<body style="margin:0px;">
<xsl:apply-templates/> <!-- Here we apply templates so, all the other
templates in our document should automatically
be called by this - no need to keep calling in other
template definitions. -->
</body>
</html>
</xsl:template>
<!-- Again, I don't know what you're trying to accomplish with the <child/> tag... You can
use <xsl:value-of select="."/> to select the text value of element a. If you are wanting
to select the value of the attribute href, we could use <xsl:value-of select="a/@href"/>
to pick up that info. Really, what fpmurphy posted is probably the easiest way to get this
data, though you could replace it with something like this:
<a href="{a/@href}"><xsl:value-of select="."/></a>
-->
<xsl:template match="SIDE">
<div style="background-color:00BBFF;width:20%;height:100%;float:right">
<div style="margin-top:10px;font-size:30px">
<xsl:copy-of select="./a"/> <!-- A <xsl:copy-of select="."/> could also be used,
but specifiying the a element is a way of making
sure that only the a element information is
selected. -->
</div>
</div>
<!-- Why are you trying to apply templates again? From what I can see, you don't need to...
<xsl:apply-templates/>
-->
</xsl:template>
<!-- Here we go again with a <children/> tag... Take that out, and then replace apply-templates
with <xsl:value-of select="."/> which will select all the text of the POST element.-->
<xsl:template match="POST">
<div style="margin-left:10px;margin-right:10px;word-wrap:break-word">
<P>
<!--<children/><xsl:apply-templates/>-->
<xsl:value-of select="."/>
</P>
</div>
</xsl:template>
<!-- Ok, almost done! Once again, clean up your code by removing the <children/> tag, then
take out that xsl:apply-templates, and actually select the value of TOP. -->
<xsl:template match="TOP">
<div style="background-color:00BBFF;width:100%;height:20%;text-align:center;font-size:60px;font-family:anythingyouwant;color:0066BB">
<div style="margin-top:10px">
<xsl:value-of select="."/>
</div>
<!--<xsl:apply-templates/>-->
</div>
</xsl:template>
</xsl:stylesheet>
<!-- Finally, just a closing thought, why don't you link to a CSS that does your formatting instead
of having those huge bits of style right in your code? Another matter of preference, but it
would definately clean up your code even more. :-) -->
Let me know if you have further questions. |
|
#8
|
|||
|
|||
|
>>I've read through the W3's XML and XSL specifications.
W3C recommendations and other standards documents are written in a terse style - typically referred to as standardese - and are unintelligible to most people trying to learn a language or programming paradigm. You should do a Web search for XSLT tutorials and work you way through as many of these as possible or sign up for a course on XML/XSLT. |
|
#9
|
||||
|
||||
|
Well.. Thank you guys. You've helped me better myself as a web designer.
One thing i've been wondering about... The CSS "height" and "width" styles.... Is there any actual way to get them actually 100% down the page? When you put "height:100%;" It does in fact go 100% of A single page. If anything in any other division extends beyond that... The previous division that has the 100% width or height stops beyond the first part of the page. |
|
#10
|
||||
|
||||
|
By the way... I DID put that piece of code that places a line break in for a reason. Sometimes when i'm writing a paper or something, I like to line break for no reason, and I see no need for having to do this:
Code:
<POST> . . . </POST> <POST> . . . </POST> Code:
<POST> . . . <br/><br/> . . . </POST> And sometimes I just randomly press the enter key. I like that. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL code won't format <child/> node |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|