I have a custom list with two columns. I want to use xsl to take the value of the fields in the first column, build a hyperlink and put it in the second column.

Please don't suggest calculated columns or lookup columns; I want to use xsl. This is what I have come up with; it doesn't give an error-page, but it doesn't do anything, either! Could somebody please help me?

<xsl:variable name="varFirstColumn">
    <xsl:value-of select="@Column1" />

<xsl:template match="FieldRef[@Name='Column2']" mode="Text_body">
    <xsl:param name="thisNode" select="."/>
        <a target="_blank"> 
            <xsl:attribute name="class">myCSSclass</xsl:attribute>    
            <xsl:attribute name="href">mydomain.com/mysite/<xsl:value-of select="$varFirstColumn"/>.html</xsl:attribute>

I tried this, too:

<xsl:template match="FieldRef[@Name='Column2']" mode="Text_body">
    <xsl:param name="thisNode" select="."/>
    <a href="mydomain.com/mysite/mypage\{Column1}" target="_blank">Dir</a>

[edit] I get an error saying The variable or parameter 'Column1' is either not defined or it is out of scope.. Now, Column1 is a Number column.

[update] The xsl does work if I don't try to look up the value of what is in Column1.

[a bit more info] I am using a custom xsl file in the _layouts directory, and using the match to make changes to any column with that fieldref name. Both columns are in the same view and in the same list.

  • What context? Are you doing this in a dataview web part or what? Oct 30, 2012 at 19:18
  • It is a custom list - no web parts, and I am editing a custom xsl file in _layouts.
    – bgmCoder
    Oct 30, 2012 at 19:49
  • Does the list view contain both columns? Which file, layouts/xsl/fldtypes*.xsl ? How do you connect it to the field? Please add all this information to your question. Oct 30, 2012 at 19:59
  • I have a custom xsl file in the /_layouts directory. In xsl, you don't have to connect it to any list directly - you can just "match" the column's field name and the changes get made. Yes, both the list and the view contain both columns.
    – bgmCoder
    Oct 30, 2012 at 20:03
  • 1
    Thanks for updating the question, now it is much better :) And yes, I've added the answer and also included some explanations and links, so hopefully next time you will have your template working from the first try! Oct 30, 2012 at 21:54

3 Answers 3


Your template matches a FieldRef element, and inside the template you're trying to get the field value as an attribute of current element (i.e. FieldRef). But the FieldRef element basically doesn't have any columns. It itself represents one column and contains some of it's properties. Ordinary FieldRef element looks as follows:

<FieldRef Name="Author" ImnHeader="TRUE" Type="User" FieldType="User"
          DisplayName="Created By" ID="1df5e554-ec7e-46a6-901d-d85a3881cb18"
          LinkToItemAllowed="Prohibited" />

To get the field value for current row, you should use $thisNode parameter, which always contains Row element, i.e. contents of $thisNode could look something like this:

  <Row ID="1"
       Title="Theories of Truth"


Having all this in mind, now it is easy to recognize the mistake. In your second code fragment, please replace {Column1} to be {$thisNode/@Column1}, and that's that.

Final code:

<xsl:template match="FieldRef[@Name='Column2']" mode="Text_body">
    <xsl:param name="thisNode" select="."/>
    <a href="mydomain.com/mysite/mypage/{$thisNode/@Column1}" target="_blank">Dir</a>

More info

It is always a good idea to have a notion of what you're doing. SharePoint list view XSLT is big and complicated thing, thus you will save much time it you explore it a bit before trying to squeeze something from it.

Good SharePoint XSLT rendering system overview can be found on MSDN:

Also it is sometimes very useful to examine examples of input and output of the transformations:


Try mode="Text_body" without the capital B in Body.

and <a href="mydomain.com/mysite/mypage/{$varFirstColumn}" target="_blank">Dir</a>

  • Thanks - I made the correction, but it didn't solve it.
    – bgmCoder
    Oct 30, 2012 at 19:55

Why do you need a template?

<a href="http://www.yourdomain.com/{@Column1}.html" class="yourClass">Dir</a>

Should work.


  • Well, I don't know, actually! I don't really know anything about xsl - I'm only at the level of hacking it at the moment. If I didn't use a template, where in my xsl file would I put your line of code?
    – bgmCoder
    Oct 30, 2012 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.