2

Suppose I have a key defined in an xslt file in SharePoint Designer 2010 as:

<xsl:key name="Years" match="/dsQueryResponse/Rows/Row" use="@Date" />

Where @Date is the column, however instead of @Date, I want to use the value of the following variable:

<xsl:variable name="VarNAme">
        <xsl:choose>
           <xsl:when test="string-length(@Date) = 8">
                <xsl:value-of select="substring(@Date, 5, 4)"></xsl:value-of>
            </xsl:when>
            <xsl:when test="string-length(@Date) = 9">
                <xsl:value-of select="substring(@Date, 6, 4)"></xsl:value-of>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring(@Date, 7, 4)"></xsl:value-of>
            </xsl:otherwise>
        </xsl:choose>   
</xsl:variable>

If there is a better way (one-liner) to get just the year from a date, I'd welcome that as well. I want to use generate-id to get distinct years (not dates, years).

halfer
  • 19,824
  • 17
  • 99
  • 186
anpatel
  • 1,952
  • 4
  • 19
  • 36

1 Answers1

4
<xsl:key 
  name="Years" 
  match="/dsQueryResponse/Rows/Row" 
  use="substring(@Date, string-length(@Date) - 3, 4)"
/>

Hint

 8 - 3 = 5
 9 - 3 = 6
10 - 3 = 7

;-)

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • GENUIS!! THANK YOU, wait let me test it then UpVote thee, it worked, I don't know why I didn't do that.. I can't accept an answer in 6 minutes so, I'll accept it tomorrow! THANK YOU, Tomalak, *Virtual Hug* – anpatel Jan 20 '12 at 16:14
  • @MyName: You are welcome. Sometimes the wood is difficult to see. ;) – Tomalak Jan 20 '12 at 16:18