SharePointコンテンツクエリWebパーツを使用しています。私はあることが望まれるHTML出力を持っています
<ul>
<li>
<img src="{RowAttribute-Url}" />
</li>
<li>
<img src="{RowAttribute-Url}" />
</li>
</ul>
<table>
<tr>
<td>{RowAttribute-Title}</td>
<td>{RowAttribute-Title}</td>
</tr>
</table>
CQWPの入力xmlは次のとおりです。
<dsQueryResponse>
<Rows>
<Row ID="1" Title="Jane Doe" Modified="2010-10-14 14:05:14" Author="" Editor="" Created="2010-10-14 11:50:35" ArticleStartDate="2010-10-01 00:00:00" Style="OutputTemplateName" GroupStyle="DefaultHeader" __begincolumn="True" __begingroup="False"></Row>
<Row ID="2" Title="John Doe" Modified="2010-10-14 14:05:29" Author="" Editor="" Created="2010-10-14 13:17:10" ArticleStartDate="2010-10-01 00:00:00" Style="OutputTemplateName" GroupStyle="DefaultHeader" __begincolumn="False" __begingroup="False"></Row>
</Rows>
</dsQueryResponse>
したがって、Webパーツがxsltに、特定のスタイルまたは出力テンプレートをレンダリングする必要があることを「通知」することがわかります。行で2番目のテンプレートを再実行したいのですが、これを行う最も簡単な方法は、最初の実行後にスタイル属性を置き換えることだと思いました。
最初の実行では、各行に一連のliタグをレンダリングし、2番目の実行ではtrsを実行します。
ItemStyleテンプレートを再度呼び出す前に、xsl-copyを使用して「OutputTemplateName」を置き換えることは可能ですか?
これが外側と内側のスタイルシートのxsltです(内側はitemstylesです)
<xsl:template name="OuterTemplate">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
<xsl:variable name="RowCount" select="count($Rows)" />
<xsl:variable name="IsEmpty" select="$RowCount = 0" />
<div id="container">
<div id="inner-container">
<xsl:choose>
<xsl:when test="$IsEmpty">
<xsl:call-template name="OuterTemplate.Empty" >
<xsl:with-param name="EditMode" select="$cbq_iseditmode" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="OuterTemplate.Body">
<xsl:with-param name="Rows" select="$Rows" />
<xsl:with-param name="FirstRow" select="1" />
<xsl:with-param name="LastRow" select="$RowCount" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</div>
</div>
</xsl:template>
<xsl:template name="OuterTemplate.Body">
<xsl:param name="Rows" />
<xsl:param name="FirstRow" />
<xsl:param name="LastRow" />
<div id="container-rotator">
<ul>
<xsl:for-each select="$Rows">
<xsl:variable name="CurPosition" select="position()" />
<xsl:if test="($CurPosition >= $FirstRow and $CurPosition <= $LastRow)">
<xsl:call-template name="OuterTemplate.CallItemTemplate">
<xsl:with-param name="CurPosition" select="$CurPosition" />
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</ul>
</div>
<h5>
<xsl:value-of select="ddwrt:FormatDateTime(string(/dsQueryResponse/Rows/Row[1]/@ArticleStartDate), 1033, 'MMMM')"/></h5>
<table>
<!-- before calling this foreach.. would i do the copy? -->
<xsl:for-each select="$Rows">
<xsl:variable name="CurPosition" select="position()" />
<xsl:if test="($CurPosition >= $FirstRow and $CurPosition <= $LastRow)">
<xsl:call-template name="OuterTemplate.CallItemTemplate">
<xsl:with-param name="CurPosition" select="$CurPosition" />
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</table>
<div>
<a title="" href="/sites/sitename/Pages/page.aspx" target="">A Page Link</a>
</div>
<div>
<a href="#">Another Page</a>
</div>
</xsl:template>
そして、アイテムテンプレートは下にありますこれは私がほぼ複製したいテンプレートですが、代わりにtrsを使用し、新しい「スタイル」も提供します
<xsl:template name="OutputTemplateName" match="Row[@Style='OutputTemplateName']" mode="itemstyle">
<xsl:param name="CurPos" />
<xsl:choose>
<xsl:when test="$CurPos = 1">
<li class="show">
<img src="{$SafeImageUrl}" />
</li>
</xsl:when>
<xsl:otherwise>
<li>
<img src="{$SafeImageUrl}" />
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
したがって、要約すると、最初に順序付けされていないリストに入れ、次にテーブルに入れたい一連の行があります...これらはすべてHTMLとして出力されますが、1つの外部変換にのみ送信できます。
概念的な提案でさえ役立つでしょう。さらに発見したら、この投稿を更新し続けます。
以下では、承認された回答を使用して次のことを行いました**
以下の答えを使用して、上記に必要な変更を説明します。
メインラッパーxsltで、次のことを行いました。
<xsl:template name="OuterTemplate.CallItemTemplate">
<xsl:param name="CurPosition" />
<xsl:param name="Mode" />
<xsl:choose>
<xsl:when test="$Mode = 'table'">
<xsl:apply-templates select="." mode="table">
<xsl:with-param name="CurPos" select="$CurPosition" />
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$Mode = 'listitem'">
<xsl:apply-templates select="." mode="listitem">
<xsl:with-param name="CurPos" select="$CurPosition" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="itemstyle">
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
そして、1つではなく2つのアイテムテンプレートがあります。
<xsl:template name="TemplateNameList" match="Row[@Style='TemplateName']" mode="listitem">
<xsl:param name="CurPos" />
<xsl:variable name="SafeImageUrl">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$CurPos = 1">
<li class="show">
<img src="{$SafeImageUrl}" />
</li>
</xsl:when>
<xsl:otherwise>
<li>
<img src="{$SafeImageUrl}" />
</li>
</xsl:otherwise>
</xsl:choose>