我正在编写一个 XSLT 模板,需要为 xml 站点地图输出有效的 xml 文件。
<url>
<loc>
<xsl:value-of select="umbraco.library:NiceUrl($node/@id)"/>
</loc>
<lastmod>
<xsl:value-of select="concat($node/@updateDate,'+00:00')"/>
</lastmod>
</url>
不幸的是,输出的 URL 包含撇号 - /what's-new.aspx
我需要逃避 ' 到'
对于谷歌站点地图。不幸的是,我尝试过的每一次尝试都会处理字符串 ''
' 就好像它是 ''' 一样,这是无效的 - 令人沮丧。 XSLT 有时会让我发疯。
对技术有什么想法吗? (假设我可以找到 XSLT 1.0 模板和函数的方法)
所以你有了'
在您的输入中,但您需要字符串
在你的输出中?
在您的 XSL 文件中,替换'
with &apos;
, using 这个查找/替换实现(除非您使用 XSLT 2.0):
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
这样称呼它:
<loc>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="umbraco.library:NiceUrl($node/@id)"/>
<xsl:with-param name="replace" select="'"/>
<xsl:with-param name="by" select="&apos;"/>
</xsl:call-template>
</loc>
问题是'
由 XSL 解释为'
. &apos;
将被解释为'
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)