Little Goat Posted March 28, 2006 Share Posted March 28, 2006 HiI’m new at XSLT and just for fun I decided to try making an XSLT file that makes it so that anyone can put in their content in the XML file and the XSLT file will make a nice web page out of it. I’m trying to make it so that whenever a user (or anyone else) puts <newline/> in the code, the XSLT will put a <br /> tag in the code. Right now it doesn’t do anything. Here are my filesXSLT <?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> <title><xsl:value-of select="page/title"/></title> <style type="text/css"> <xsl:value-of select="page/style"/> </style> </head> <body> <table width="100%"> <tr> <td colspan="2" id="header"><xsl:value-of select="page/title"/></td> </tr> <tr> <td id="links" width="20%"> <xsl:for-each select="page/links/link"> <xsl:variable name="href" select="to"/> <a href="{$href}"><xsl:value-of select="show"/></a><br /> </xsl:for-each> </td> <td id="content" width="80%"> <xsl:value-of select="page/content"/> <p><xsl:apply-templates select="newline"/></p> </td> </tr> </table> </body> </html> </xsl:template> <xsl:template match="newline"> <br/> </xsl:template></xsl:stylesheet> and XML <?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?><page> <title>This will show in the title space and the header</title> <style> body {background-color:aqua;} #header {background-color:teal; font-size:300%; font-family:Bradley Hand ITC,forte; text-align:center; height:128; color:white;} #links {background-color:red; font-size:150%; height:250;} #content {background-color:#ffffee; text-align:center;} </style> <links> <link> <show>Home</show> <to>example.htm</to> </link> <link> <show>home2</show> <to>example.htm</to> </link> </links> <content>Content here<newline/>this break doesn’t work </content></page> Thanks in advanceLG Link to comment Share on other sites More sharing options...
paetje Posted March 28, 2006 Share Posted March 28, 2006 http://w3schools.invisionzone.com/index.php?showtopic=2855Take a look a my code. In the second XSL file the transform file search for "volgenderegel". Good luck Link to comment Share on other sites More sharing options...
Little Goat Posted March 29, 2006 Author Share Posted March 29, 2006 Hi,thanks for answering paetje, I tried your code , but I guess I don't understand what is taking place. I altered my XSL File to this; <?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> <title><xsl:value-of select="page/title"/></title> <style type="text/css"> <xsl:value-of select="page/style"/> </style> </head> <body> <table width="100%"> <tr> <td colspan="2" id="header"><xsl:value-of select="page/title"/></td> </tr> <tr> <td id="links" width="20%"> <xsl:for-each select="page/links/link"> <xsl:variable name="href" select="to"/> <a href="{$href}"><xsl:value-of select="show"/></a><br /> </xsl:for-each> </td> <td id="content" width="80%"> <xsl:value-of select="page/content"/> </td> </tr> </table> </body> </html> </xsl:template> <xsl:template match="newline"> <br/> <xsl:apply-templates/> </xsl:template></xsl:stylesheet> But it still doesn't work. the XML file is the same.could you try to explain this to me or show me how to do it in my code?Oh and one more thing. does anyone know how to change the username on this forum? thanks, LG Link to comment Share on other sites More sharing options...
paetje Posted March 29, 2006 Share Posted March 29, 2006 What I see at a fist look is just fine, but I wonder if the dubble closing of the <xsl:template> does somthing wrong. I think you have to put only </xsl:template><xsl:template match="newline"> <BR/> <xsl:apply-templates/></xsl:stylesheet> afther the HTML part Link to comment Share on other sites More sharing options...
boen_robot Posted March 29, 2006 Share Posted March 29, 2006 Actually, that part is correct. There must be a closing tag for the template element after all.The error I see is that you have used <xsl:value-of /> for the content. There should only be <xsl:apply-templates/> at that very spot. Link to comment Share on other sites More sharing options...
Little Goat Posted April 3, 2006 Author Share Posted April 3, 2006 sorry I took a while to reply.about the <xsl:value-of> tag, I need the content and the template to be put into that space.I tried replacing it with an <xsl:apply-templates> tag and it shows all the content of the xml file, not just the content section. :)Here is the newest version of my XSL file. <?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> <title><xsl:value-of select="page/title"/></title> <style type="text/css"> <xsl:value-of select="page/style"/> </style> </head> <body> <table width="100%"> <tr> <td colspan="2" id="header"><xsl:value-of select="page/title"/></td> </tr> <tr> <td id="links" width="20%"> <xsl:for-each select="page/links/link"> <xsl:variable name="href" select="to"/> <a href="{$href}"><xsl:value-of select="show"/></a><br /> </xsl:for-each> </td> <td id="content" width="80%"> <xsl:apply-templates/> </td> </tr> </table> </body> </html> </xsl:template> <xsl:template match="break"> <br/> <xsl:apply-templates/> </xsl:template></xsl:stylesheet> thats the one that shows all the XML content.same xml.if anyone knows how to make xsl transfer tags that are in the code, that would work, but I would prefer this.I don't know if I'm explaining it well, so if you can't figure out what I mean, please try it.thanks, LG Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now