[英]get xpath following sibling to make use of a template with its value
我有以下XSLT:
<xsl:if test="$CurPos mod 2 =1">
<li style="width:604px;">
<div class="content-left" style="width:300px; height:290px;float:left;">
<xsl:if test="string-length($SafeImageUrl) != 0">
<div class="images-area-left">
<a href="{$SafeLinkUrl}" target="{$LinkTarget}">
<img class="image" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" />
</a>
<div class="Heading-desc">
<span class="NewsHeading"><h4><xsl:value-of select="@Title"/></h4></span>
<span class="Desc">
<xsl:value-of select="substring(@Comments,0,200)"/>
<xsl:if test="string-length(@Comments) > 200">…</xsl:if>
<a href="{$SafeLinkUrl}" class="ReadMore"> Read More</a>
</span>
</div>
</div>
</xsl:if>
</div>
<div class="content-right" style="float:right; width:300px; height:290px;">
<xsl:value-of select="following-sibling::*[1]/@PublishingRollupImage" disable-output-escaping="yes" />
<span class="NewsHeading"><h4><xsl:value-of select="following-sibling::*[1]/@Title"/></h4></span>
<span class="Desc" style="display:block; width:280px;"><xsl:value-of select="substring(following-sibling::*[1]/@Comments,0,200)"/>
<xsl:if test="string-length(following-sibling::*[1]/@Comments) > 200">…</xsl:if><a href="{$SafeLinkUrl}" class="ReadMore"> Read More</a>
</span>
</div>
</li>
</xsl:if>
有一个变量$ SafeLinkUrl来自另一个模板,该模板获取当前行的页面URL。 由于我仍在当前节点上时正在跟随同级,因此无法获取以下同级的URL。
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
============>指向此模板
<xsl:template name="OuterTemplate.GetSafeLink">
<xsl:param name="UrlColumnName"/>
<xsl:if test="$UseCopyUtil = 'True'">
<xsl:value-of select="concat($RootSiteRef,'/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=',@ID,'&ListId=',@ListId,'&WebId=',@WebId,'&SiteId=',$SiteId,'&Source=',$Source)"/>
</xsl:if>
<xsl:if test="$UseCopyUtil != 'True'">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
这可以调用====>
<xsl:template name="OuterTemplate.GetSafeStaticUrl">
<xsl:param name="UrlColumnName"/>
<xsl:variable name="Url">
<xsl:call-template name="OuterTemplate.FormatColumnIntoUrl">
<xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="cmswrt:EnsureIsAllowedProtocol($Url)"/>
</xsl:template>
再次调用另一个模板,=====>
<xsl:template name="OuterTemplate.FormatColumnIntoUrl">
<xsl:param name="UrlColumnName"/>
<xsl:variable name="Value" select="@*[name()=$UrlColumnName]"/>
<xsl:if test="contains($DataColumnTypes,concat(';',$UrlColumnName,',URL;'))">
<xsl:call-template name="OuterTemplate.FormatValueIntoUrl">
<xsl:with-param name="Value" select="$Value"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="not(contains($DataColumnTypes,concat(';',$UrlColumnName,',URL;')))">
<xsl:value-of select="$Value"/>
</xsl:if>
</xsl:template>
这是实际的XML: https : //gist.github.com/4380967
容器的XSL: https : //gist.github.com/4389989
单个行的XSL: https : //gist.github.com/4389997
我无法将$ SafeLinkUrl用于以下同级兄弟:: * [1],因为它适用于当前项目而不适用于直接同级兄弟。 如何使变量也适用于兄弟?
用途 :
<xsl:variable name="SafeLinkUrl">
<xsl:for-each select="following-sibling::*[1]">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
甚至更好的是,在模板中添加第二个参数:
<xsl:template name="OuterTemplate.GetSafeLink">
<xsl:param name="UrlColumnName"/>
<xsl:param name="pContext" select="."/>
<xsl:if test="$UseCopyUtil = 'True'">
<xsl:value-of select="concat($RootSiteRef,'/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=', $pContext/@ID,'&ListId=',$pContext/@ListId,'&WebId=',$pContext/@WebId,'&SiteId=',$pContext/$SiteId,'&Source=',$Source)"/>
</xsl:if>
<xsl:if test="$UseCopyUtil != 'True'">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
对其他两个模板执行此操作。 调用两个内部模板中的任何一个时,请指定$pContext
参数。
然后调用最外层模板,将$pContext
参数指定为following-sibling::*[1]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.