We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,466 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

XSL Link from value-of

Hi,

I am totally new to XSL and this is my first time coding it with it. I have HTML and CSS experience and trying to figure out how to integrate it all together for a SharePoint view.

Basically I have an XML file with about 3 records, each having a Title attribute and a URL attibute among others. Now what I want to do is have the Title attribute appear as a URL so when the title is linked, it will navigate to the URL that is specified in the URL attribute. Similar to how <a href="url">Link text</a> works...how would I go about doing this?

So far I have tried:

<a href="'<xsl:value-of select="url"/>'"><xsl:value-of select="title"/></a>

Would I need to accomplish this using an XSL variable? I have this to assign the value to the variable but it does not work:

<xsl:variable name="temp" select="'<xsl:value-of select="url"/>'" />

Any help with this would be much appreciated!!!!! :)

2
Contributors
3
Replies
2 Days
Discussion Span
10 Months Ago
Last Updated
4
Views
tudorH
Newbie Poster
16 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Alright, I've figured out how to create the variables but how do I create the link? I can't seem to use a href. This is what I was trying:

        <xsl:variable name="titleVar"> 
          <xsl:value-of select="title"/>
        </xsl:variable>

        <xsl:variable name="urlVar">
          <xsl:value-of select="link"/>
        </xsl:variable>

        <td><a href="$urlVar">"$titleVar"</a></td>

Any idea what I'm doing wrong?

tudorH
Newbie Poster
16 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

EDIT: I may have figured it out but wont be able to try in SharePoint until next week. Can anyone confirm that this is the right way to do it?

<xsl:variable name="urlVar">
   <xsl:value-of select="link"/>
</xsl:variable>

<td><a href="{$urlVar}"><xsl:value-of select="title"/></a></td>
tudorH
Newbie Poster
16 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes"/>

  <xsl:variable name ="urlVar"></xsl:variable>
  <xsl:variable name="title"></xsl:variable>

  <xsl:template match="*">
    <xsl:element name="td">
      <xsl:element name="a">
        <xsl:attribute name="href">
          <xsl:value-of select ="$urlVar"/>
        </xsl:attribute>
        <xsl:value-of select="$title"/>
      </xsl:element>
    </xsl:element>
  </xsl:template>

  </xsl:stylesheet>

I've produced what your after using this code. It is worth noting that if you enable Indenting in the stylesheet it wont give the flat look you are after.

MikeyIsMe
Master Poster
798 posts since Nov 2010
Reputation Points: 88
Solved Threads: 69
Skill Endorsements: 10

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.5267 seconds using 2.74MB