SharePointのXSLリンクの話です。中々情報がないので苦労しました。
公式はこちらですので、先にご覧ください。
[方法] リスト ビューでのフィールドのレンダリングをカスタマイズする
https://msdn.microsoft.com/ja-jp/library/office/ff606773(v=office.14).aspx
サーバー表示の場合、次のXSLコードが既定で動作します。
%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl
XSLリンクでは、指定した名前だったり属性をもつフィールドで、この既定の規則を上書きします。
xsl:template
タグのmatch属性でフィールドの内部名をマッチングするわけですが、
- 下記のサンプルコードではFooがそれにあたります。
- fldtypes.xslからオーバーライドする既定のtemplateを探し、mode属性を探します。
- xslリンクファイルで、xml:tempalteを定義します。その際、mode属性には上記のものを記述します。
mode属性は、例えばフィールドがDateTime型だったら、mode="DateTime_body" といったような。
フィールドの型の英語表記がわからなかったら以下のドキュメントを参考に。
Field 要素 (フィールド)
https://msdn.microsoft.com/ja-jp/library/office/aa979575.aspx
※Type属性のあたりに詳しく記述があります。
さて、今回私がXSLリンクで上書きしたいフィールドは選択肢(Choise) 型でした。
困ったことにfldtypes.xslでどのテンプレートが該当するのかわかりませんでした(汗)
よくよくxslを読むと、いずれでもなかったら mode=body
を指定すると!なんと!
以下のサンプルコードは選択しの数値によって、天気の日本語表記に変換するXSLです。
xslファイルはエンコードをUTF8にして保存します。
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal">
<xsl:include href="/_layouts/xsl/main.xsl"/>
<xsl:template match="FieldRef[@Name='Foo']" ddwrt:dvt_mode="body" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="fieldValue">
<xsl:call-template name="FieldRef_ValueOf_DisableEscape">
<xsl:with-param name="thisNode" select="$thisNode" />
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$fieldValue=1">
晴れ
</xsl:when>
<xsl:when test="$fieldValue=2">
くもり
</xsl:when>
<xsl:when test="$fieldValue=3">
雨
</xsl:when>
<xsl:when test="$fieldValue=4">
その他
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
さて、これをWebパーツを「サーバー表示」にして、の XSLのURLを指定して出来上がりです。