我正在使用SharePoint内容查询Web部件。我有需要的HTML输出为修改XSLT中的属性值并再次调用模板
<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,它应该呈现一个特定的样式或输出模板。我想在行上重新运行第二个模板,我认为最简单的方法是在第一次运行后替换style属性。
第一次运行我想为每一行渲染一系列li标签,第二遍经过我想要做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格式输出,但我只能将它发送到一个外部变换中。
即使任何概念性建议都会有所帮助。我会继续更新这篇文章,因为我发现更多。
下面我用的接受的答案做以下**
使用回答以下我将阐述需要上述的变化。
在主包装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>
然后我有两个项目模板,而不是一个。
<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>
尚不清楚你想要什么。请提供要应用转换的源XML文档。另外,对于这个完全XML文档提供了转换所需的结果。最后,描述转换的所需属性。 – 2010-10-14 22:44:50
当然,我会看看我能做些什么 – 2010-10-14 22:50:36
只是未成年人。我已经看到你的模式编辑。我认为这并没有帮助你减少样式表逻辑。这一定是因为那些名为模板...我认为你的样式表需要重构更多的模式匹配...另外,混合数据和样式信息并不是一个好的做法:你可以将该样式信息放入布局文档中,然后填充该文件与数据。 – 2010-10-15 22:29:52