手順 3 : XSLT 変換コードの作成
ユーザー設定の検索 Web パーツ コードは検索結果を XML データに変換した後、XSLT 変換を XML に適用して、ブラウザでの表示用にフォーマットします。このサンプルで使用する変換コードは、コア検索結果 Web パーツで使用される XSLT 変換の変更されたバージョンです。詳細については、「Enterprise の主要な検索結果の XSLT 変換」を参照してください。
注意
このコード サンプルで指定される productXSL.xsl への仮想パスは _layouts virtual ディレクトリで、これは物理パス \Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\. に変換されます。productXSL.xsl を別の場所に保存する場合は、正しく動作するようにサンプルのパスを変更する必要があります。
XSLT 変換コードを作成するには
以下のパスに productXSL.xsl ファイルを作成します。
\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\
ファイルを編集するには、Visual Studio 2005 などの開発ツールやメモ帳などのテキスト エディタを使用することができます。
以下のコードを productXSL.xsl に追加します。
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:template match="/"> <xsl:variable name="Rows" select="/All_Results/Result" /> <xsl:variable name="RowCount" select="count($Rows)" /> <xsl:variable name="IsEmpty" select="$RowCount = 0" /> <xsl:choose> <xsl:when test="$IsEmpty"> <xsl:call-template name="dvt_1.empty" /> </xsl:when> <xsl:otherwise> <xsl:call-template name="dvt_1.body"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="dvt_1.empty"> <span class="srch-description" id="CSR_NO_RESULTS"> No results matching your search were found. <ol> <li>Check your spelling. Are the words in your query spelled correctly?</li> <li>Try using synonyms. Maybe what you're looking for uses slightly different words.</li> <li>Make your search more general. Try more general terms in place of specific ones.</li> <li>Try your search in a different scope. Different scopes can return different results.</li> </ol> </span> </xsl:template> <xsl:template name="dvt_1.body"> <xsl:apply-templates /> </xsl:template> <xsl:template match="Result"> <xsl:variable name="id" select="PRODUCTID"/> <xsl:variable name="url" select="PATH"/> <span class="srch-Title"> <a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}"> <xsl:value-of select="PRODUCTNAME"/></a> <br/> </span> <span class="srch-Metadata"> <xsl:call-template name="DisplayString"> <xsl:with-param name="str" select="PRODUCTID" /> <xsl:with-param name="prop">Product ID:</xsl:with-param> </xsl:call-template> <br/> </span> <span class="srch-URL"> <a href="{$url}" id="{concat('CSR_U_',$id)}" title="{$url}"> <xsl:value-of select="PATH"/> </a><br/><br/> </span> </xsl:template> <xsl:template name="DisplayString"> <xsl:param name="str" /> <xsl:param name="prop" /> <xsl:if test='string-length($str) > 0'> <xsl:value-of select="$prop" />  <xsl:value-of select="$str" /> </xsl:if> </xsl:template> </xsl:stylesheet>
productXSL.xsl XSLT 変換ファイルの完全なコードは「サンプル :AdventureWorks 検索サンプル XSLT 変換」から入手できます。
See Also
タスク
[ウォークスルー] AdventureWorks ビジネス データ アプリケーション サンプル用の ASP.NET Web パーツを作成する
手順 1 : カスタム検索 Web パーツのプロジェクトを設定する