prime Posted November 26, 2007 Share Posted November 26, 2007 I have a rather simple XML document written below: <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="toollinks.xsl"?> <toollinks> <link> <name>Travian Tool</name> <description>Some great useful tools and utilities, Simply click amongst the tools on the right hand menu to view in-active finders and such, very useful</description> <sitelink>http://traviantool2.ww7.be/index.php?lang=com</sitelink> </link> <link> <name>Travian Toolbox</name> <description>Another Site with a ton of useful tools and utilities</description> <sitelink>http://www.traviantoolbox.com/index.php?lang=en</sitelink> </link> <link> <name>Battle Report publisher</name> <description>A great alternative tool to copy battle reports into, it analyzes the information you provide and rebuilds it into a user friendly format</description> <sitelink>http://travilog.org.ua</sitelink> </link> <link> <name>9 and 15 croppers finder</name> <description>A good cropfinder utility</description> <sitelink>http://asite.110mb.com/cropfinder.php</sitelink> </link> <link> <name>Travian Flash map</name> <description>With Flash map you can: observe villages, alliances and player positions. Get short info about village. Go to player/alliance profile or get straight to the village position in Travian. Get a direct link for the map and share it. Calculate distance between villages and travel time of you army</description> <sitelink>http://travian.org.ua/com</sitelink> </link> <link> <name>Travian World Analyzer</name> <description>Using it you can easily find inactive neighbours for farming, view population growth of your enemies, track all the events in the world. For example: village conquering, players changing alliance and the foundation of new villages. In the "day overview" page, you can see which villages and players have the highest population growth, which villages are under attack and the greatest losers.</description> <sitelink>http://travian.ws/</sitelink> </link> </toollinks> Which I am using Xslt to transform into Html like thus <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body bgcolor="black"> <h2 align="center"><font color="red">Tools for Travian</font></h2> <table border="1" bgcolor="orange"> <tr bgcolor="#9acd32"> <th align="left">Name</th> <th align="left">Description</th> <th align="left">Link</th> </tr> <xsl:for-each select="toollinks/link"> <xsl:sort select="name"/> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="description"/></td> <td><xsl:value-of select="sitelink"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Which works fine, now I tried to get rid of the link display and just use that hyperlink for the name section like: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body bgcolor="black"> <h2 align="center"><font color="red">Tools for Travian</font></h2> <table border="1" bgcolor="orange"> <tr bgcolor="#9acd32"> <th align="left">Name</th> <th align="left">Description</th> </tr> <xsl:for-each select="toollinks/link"> <xsl:sort select="name"/> <tr> <td><a href="<xsl:value-of select="sitelink"/>"><xsl:value-of select="name"/></a></td> <td><xsl:value-of select="description"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> However I cant get it to work since it is mal-formed XML which I can understand, but I'm not sure how to do this is well formed XML. Any help would be appreciated thx Quote Link to comment https://forums.phpfreaks.com/topic/78878-xslt-hyperlink-cant-get-to-work/ Share on other sites More sharing options...
effigy Posted November 27, 2007 Share Posted November 27, 2007 Use xsl:element and xsl:attribute: Example. Quote Link to comment https://forums.phpfreaks.com/topic/78878-xslt-hyperlink-cant-get-to-work/#findComment-400376 Share on other sites More sharing options...
prime Posted November 27, 2007 Author Share Posted November 27, 2007 Actually I just had someone show me how to do it this way <xsl:element name="a"> <xsl:attribute name="href"><xsl:value-of select="sitelink"/></xsl:attribute> <xsl:value-of select="name"/> </xsl:element> I see that the a element is created with an attribute href with the vlaue of the xml element sitelink, so this I understand how it's working. Now I just need to find some sort of way to do a nl2br and I'll be set, this xslt language is hard to get to grips with, it's similar to scripting languages in some ways and completely different in others Quote Link to comment https://forums.phpfreaks.com/topic/78878-xslt-hyperlink-cant-get-to-work/#findComment-400669 Share on other sites More sharing options...
effigy Posted November 28, 2007 Share Posted November 28, 2007 Yes, XSLT is unique. See if this does the job. Quote Link to comment https://forums.phpfreaks.com/topic/78878-xslt-hyperlink-cant-get-to-work/#findComment-401166 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.