Nov 21, 2009

XSL Need Help Translating XML To HTML Hyperlink

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > Miscellaneous Scripting Languages & Ideas

XSL Need Help Translating XML To HTML Hyperlink

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

imagine the following XML

CODE
<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

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



at first i tried


CODE
<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 ??

 

 

 


Comment/Reply (w/o sign-up)

rkage
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;
CODE
<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="links.xsl"?>

<students>
[tab][/tab]<student name="Chris">
 <link>http://www.chris.com</link>
[tab][/tab]</student>
[tab][/tab]
[tab][/tab]<student 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;
CODE
<?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.

 

 

 


Comment/Reply (w/o sign-up)

rkage
Woops, almost forgot, if you want to see the thing in action, click here example.

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

rIxXoN
Maybe you should read this?:

http://www.astahost.com/Converting-HTML-ov...XHTML-t501.html

I hope this helpd you.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for xsl, translating, xml, html, hyperlink
advertisement



XSL Need Help Translating XML To HTML Hyperlink

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com