primefalcon Posted November 26, 2007 Share Posted November 26, 2007 Ok I've written up this little xml document, no hassles no fuss <?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 there's no problem with, I've parsed with php, and alsoused a simple xsl file for a stylesheet, works fine.but since I'm very new to XSL I seem to be having a problem with displaying hyperlinks in this langauge, here's an attempt I've tried, I've tried several different ways but I just cant get it, this XSL seems very simple but I just cant work out hyperlinks without resorting back to php parsing, which I'm trying not to do, anyhow here's my pitiful attempt <?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> <h2 align="center">Tools for Travian</h2> <table border="1"> <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> Any help would be appreciated thanks Link to comment Share on other sites More sharing options...
aalbetski Posted November 26, 2007 Share Posted November 26, 2007 try this<xsl:element name="a"> <xsl:text>name</xsl:text> <xsl:attribute name="href" select="sitelink"/></xsl:element> Link to comment Share on other sites More sharing options...
primefalcon Posted November 26, 2007 Author Share Posted November 26, 2007 I cant get that to actually work either :-( Link to comment Share on other sites More sharing options...
aalbetski Posted November 26, 2007 Share Posted November 26, 2007 sorry, typo in my code <xsl:element name="a"> <xsl:attribute name="href"><xsl:value-of select="sitelink"/></xsl:attribute> <xsl:text>name</xsl:text> </xsl:element> Link to comment Share on other sites More sharing options...
primefalcon Posted November 26, 2007 Author Share Posted November 26, 2007 Ok thats working but it's leaving another tiny problemthe name isn't pulling the name from the xml file its just saying name, the hyper link is working good though Link to comment Share on other sites More sharing options...
aalbetski Posted November 26, 2007 Share Posted November 26, 2007 <xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="sitelink"/></xsl:attribute><xsl:value-of select="name"/></xsl:element> Link to comment Share on other sites More sharing options...
primefalcon Posted November 26, 2007 Author Share Posted November 26, 2007 ahh beautiful and I see exactly how it was done too. Thank you very much :-) Link to comment Share on other sites More sharing options...
boen_robot Posted November 27, 2007 Share Posted November 27, 2007 You should know you can also use AVTs in simpler cases. An AVT (Attribute Value Template) is an XPath expression, written directly within the attribute's value, surrounded by parenthesis. In your case: <a href="{sitelink}"><xsl:value-of select="name"/></a> It's shorter, more readable, and I think (but I'm not really sure) faster on some XSLT processors. Link to comment Share on other sites More sharing options...
primefalcon Posted November 27, 2007 Author Share Posted November 27, 2007 Thank you a lot :-), actually I can easily see how this is being done a a element is veing created and givn an atrribute with the value of the sitelink element which is then converted over to htmlNow 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 Link to comment Share on other sites More sharing options...
boen_robot Posted November 28, 2007 Share Posted November 28, 2007 Thank you a lot :-), actually I can easily see how this is being done a a element is veing created and givn an atrribute with the value of the sitelink element which is then converted over to htmlNow 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 othersThat has been one of the hardest things for me in XSLT 1.0. In XSLT 2.0, there's a built in function for that. Any way I think of, not involving extension, involves a sort of an extension...By that I mean the EXSLT str:replace() function. The only way I can imagine without it is to use the template (available from that page) instead. The template itself is technically not an extension, since it realies mostly on built in XSLT 1.0 stuff (if you have support for exsl:node-set(), it will run the str:replace template faster too). And i'm not even sure if it will work in an edge case like "nl2br". Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.