我正在编写一个XSLT模板,需要为xml Sitemap输出有效的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>
Run Code Online (Sandbox Code Playgroud)
不幸的是,输出的Url包含一个撇号 - /what's-new.aspx
我需要逃避'去'谷歌Sitemap.不幸的是,我尝试过的所有尝试都将字符串' ''视为''',这是无效的 - 令人沮丧.XSLT有时会让我发疯.
对技术的任何想法?(假设我可以找到解决XSLT 1.0模板和函数的方法)
所以你有'输入,但你需要 输出中的字符串?
在您的XSL文件,替换'用&apos;,使用这种查找/替换实现(除非您使用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>
Run Code Online (Sandbox Code Playgroud)
这样称呼它:
<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>
Run Code Online (Sandbox Code Playgroud)
问题是'由XSL解释为'.&apos;将被解释为'.
| 归档时间: |
|
| 查看次数: |
19994 次 |
| 最近记录: |