gpt4 book ai didi

xslt - 如何使用 XSL 将原子提要中的相对链接转换为绝对链接?

转载 作者:行者123 更新时间:2023-12-03 14:09:16 24 4
gpt4 key购买 nike

我正在从 Confluence 中提取 Atom 提要.某些链接和图像与域 (/) 相关,因此当我在其他网站上使用提要时,图像和链接已损坏。

是否可以使用 xslt 将所有应用程序相对链接转换为绝对链接?有没有更好的方法?

Here's a sample

最佳答案

您可以使用 /feed/link/@href 的值通过查找 ="/ 为所有相对路径构建绝对路径内text()节点并将其替换为完整路径。

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom">

<xsl:template match="atom:summary[@type='html']/text()" >
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="." />
<xsl:with-param name="replace" select="'=&quot;/'" />
<xsl:with-param name="with" select="concat('=&quot;', /atom:feed/atom:link/@href, '/')"/>
</xsl:call-template>
</xsl:template>

<!--recursive template that replaces string values -->
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!--identity template -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

关于xslt - 如何使用 XSL 将原子提要中的相对链接转换为绝对链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3065239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com