为什么下面的代码不能在XSLT1.0中工作?
<xsl:template name="GenerateSummaryOld">
<xsl:param name="Content" />
<xsl:param name="Length" />
<xsl:param name="DisableOutputEscaping" />
<xsl:value-of select="substring($Content, 1, $Length)" disable-output-escaping="$DisableOutputEscaping" />
<xsl:if test="string-length($Content) > $Length"><i>...text has been shortened</i></xsl:if>
</xsl:template>在调用模板时,我使用了以下内容:
<xsl:with-param name="DisableOutputEscaping">no</xsl:with-param>我正尝试在SharePoint内容查询WebPart中执行此操作,但遇到web部件错误。如果我在模板中硬编码禁用-输出-转义为"yes“或" no”,我不会得到任何错误。
发布于 2012-12-18 12:53:36
C·M·斯珀伯格-麦昆的好答案中提供了解释。
以下是一种解决方法:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vAmp">&</xsl:variable>
<xsl:variable name="vYesNo" select="'yes'"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$vYesNo = 'yes'">
<xsl:value-of select="$vAmp" disable-output-escaping="yes"/>
</xsl:when>
<xsl:when test="$vYesNo = 'no'">
<xsl:value-of select="$vAmp" disable-output-escaping="no"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>当对任何XML文档(未使用)应用此转换时,结果为:
&如果我们替换,则为
<xsl:variable name="vYesNo" select="'yes'"/>使用的
<xsl:variable name="vYesNo" select="'no'"/>修改后的转换结果现在是
&https://stackoverflow.com/questions/13924168
复制相似问题