Jump to content
xisto Community
Sign in to follow this  
qwijibow

XSL Need Help Translating XML To HTML Hyperlink

Recommended Posts

Sorry if this sounds stupid, but im new to XML, and i just cant get my head around this problem.

imagine the following XML

<student name=chris>  <link>http://.chris.com</link><student>


i need to use XSL to translate that to a html hyperlink in the form of

<a hreh="http://chris.com">chris</a>


at first i tried


<a href=" <xsl:value-of select="student/link"/>"><xsl:value-of select="student/@name"/></a>


but that generates a nasty error, obviously because i have embedded tags.

how am i meant to solve this problem ????

i have tried storeing "chris.com" in a xsl variable, but then all i get is a hyperlink to a variable name.

google is clueless, does anyone here have any idea's ??

Share this post


Link to post
Share on other sites

Sorry about the long wait for a while. I was stomped on this one last night and my connection went off so I couldn't get to do any more testing, but I remembered how to do what you want. For the sake of completion, here is the XML file I used;


<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="links.xsl"?><students>[tab][/tab]<student name="Chris">  <link>chris.com/ name="Kage">  <link>http://kage.astahost.com</link>[tab][/tab]</student></students>

So to do what you want, just assign the tag <a> and then use the <xsl:attribute name=" "></xsl: attribute>Text for link here</a> So the complete code I used is;


<?xml version="1.0"?><xsl:stylesheet version="1.0"                             xmlns:xsl="http://www.w3.org/1999/XSL/Transform/ ; <xsl:template match="/"><html><body><xsl:for-each select="students/student"> <a><xsl:attribute name="href">       <xsl:value-of select="link"/></xsl:attribute>       <xsl:value-of select="@name"/>       </a>      <br /></xsl:for-each></body></html></xsl:template></xsl:stylesheet>

Hope this helped. It certainly relit a spark in my head about XML. If you've any qu's in the future on XML, just give me a buzz.


Share this post


Link to post
Share on other sites

Thanks, thats exactly what i needed, i didnt even know htat xsl:attribute existed.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.