Sharepoint XSL正在更改指向%20的链接中的空格
我需要更改由MOSS07自动创建的带有空格的链接,使其包含%20Sharepoint XSL正在更改指向%20的链接中的空格,sharepoint,sharepoint-2007,xslt,Sharepoint,Sharepoint 2007,Xslt,我需要更改由MOSS07自动创建的带有空格的链接,使其包含%20 例如: {$SafeLinkURL} 哪一个是空间的输出 如果有人能解释这一点,请做 提前感谢, 尼克这个问题到底要问什么还不清楚 如果问题是将给定字符串中的所有空格字符替换为“%20”,那么这里有一个XSLT解决方案: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output
例如:
{$SafeLinkURL}
哪一个是空间的输出
如果有人能解释这一点,请做 提前感谢,
尼克这个问题到底要问什么还不清楚 如果问题是将给定字符串中的所有空格字符替换为“%20”,那么这里有一个XSLT解决方案:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="link/text()[contains(., ' ')]">
<xsl:call-template name="replace"/>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="pText" select="."/>
<xsl:param name="pTarget" select="' '"/>
<xsl:param name="pReplacement" select="'%20'"/>
<xsl:choose>
<xsl:when test="not(contains($pText, $pTarget))">
<xsl:value-of select="$pText"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=
"substring-before($pText, $pTarget)"/>
<xsl:value-of select="$pReplacement"/>
<xsl:call-template name="replace">
<xsl:with-param name="pText" select=
"substring-after($pText, $pTarget)"/>
<xsl:with-param name="pTarget" select="$pTarget"/>
<xsl:with-param name="pReplacement"
select="$pReplacement"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<link>http://stackoverflow.com/example of spaces</link>
<link>http://stackoverflow.com/example%20of%20spaces</link>
当此转换应用于此XML文档时:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="link/text()[contains(., ' ')]">
<xsl:call-template name="replace"/>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="pText" select="."/>
<xsl:param name="pTarget" select="' '"/>
<xsl:param name="pReplacement" select="'%20'"/>
<xsl:choose>
<xsl:when test="not(contains($pText, $pTarget))">
<xsl:value-of select="$pText"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=
"substring-before($pText, $pTarget)"/>
<xsl:value-of select="$pReplacement"/>
<xsl:call-template name="replace">
<xsl:with-param name="pText" select=
"substring-after($pText, $pTarget)"/>
<xsl:with-param name="pTarget" select="$pTarget"/>
<xsl:with-param name="pReplacement"
select="$pReplacement"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<link>http://stackoverflow.com/example of spaces</link>
<link>http://stackoverflow.com/example%20of%20spaces</link>
http://stackoverflow.com/example 空间的
生成所需的正确结果:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="link/text()[contains(., ' ')]">
<xsl:call-template name="replace"/>
</xsl:template>
<xsl:template name="replace">
<xsl:param name="pText" select="."/>
<xsl:param name="pTarget" select="' '"/>
<xsl:param name="pReplacement" select="'%20'"/>
<xsl:choose>
<xsl:when test="not(contains($pText, $pTarget))">
<xsl:value-of select="$pText"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=
"substring-before($pText, $pTarget)"/>
<xsl:value-of select="$pReplacement"/>
<xsl:call-template name="replace">
<xsl:with-param name="pText" select=
"substring-after($pText, $pTarget)"/>
<xsl:with-param name="pTarget" select="$pTarget"/>
<xsl:with-param name="pReplacement"
select="$pReplacement"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<link>http://stackoverflow.com/example of spaces</link>
<link>http://stackoverflow.com/example%20of%20spaces</link>
http://stackoverflow.com/example%20of%20spaces
提到的XSLT 2.0函数包括:
有关详细规范和示例,请参见链接。在您的情况下(如果您可以使用XSLT2.0处理器),fn:iri-to-uri()
会解决您的问题
但是这些函数都不能在当前的XSLT1.0环境中工作。因此,请把这篇文章作为其他人今后的参考。我的意见是
<a href="a/file name.pdf">
这里的问题是+而不是%20。所以我用replace($encoded name,[+]','%20')
要复制的代码:
<xsl:transform version="2.0"
xmlns:u="java:java.net.URLEncoder"
>
<xsl:param name="encoded-name" select="u:encode(@href, 'UTF-8')"/>
<xsl:param name="final-name" select="replace($encoded-name, '[+]', '%20')"/>
最终输出:
<a href="a%2Ffile%20name.pdf">
问得好,+1。有关完整的XSLT 1.0解决方案,请参见我的答案。:)不是在评判,但是你不认为大量的解码/编码字符串扩展函数更适合吗?使用URL的事情通常会很快变得更加复杂。@Flack:当然,但他似乎在问如何使用XSLT来实现这一点。我认为有一个标准的XPath2.0函数可以精确地进行这种URL编码。但是,我想,EXSLT字符串或类似的附加链接仍然值得一提:)@Flack:谢谢。他无法使用EXSLT,因为他正在共享点内使用MSXML。