2010-06-17 51 views
4

我从Confluence拉Atom饲料。某些链接和图片与域(/)相关,因此当我在其他网站上使用Feed时,图片和链接将被打破。如何将原子提要中的相对链接转换为绝对XSL?

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

Here's a sample

+0

是的,你可以将链接从相对转换为绝对。用原子样本我们可以精确地回答。 – 2010-06-17 21:22:06

+0

我已经添加了一个示例Feed的链接。 – jrummell 2010-06-18 03:36:57

回答

3

您可以使用/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> 
+0

很好的答案!我认为你需要*用**添加一个斜线*到你的** $。此外,在这种情况下,您可以使用** summary [@ type ='html']/text()** – 2010-06-18 12:51:51

+0

@Ajjandro来优化文本()模式 - 您是对的,谢谢您的反馈。我调整了样式表。 – 2010-06-18 13:24:17

+0

工作,谢谢!我们的Confluence安装位于www.example.com/confluence,所以我必须将替换参数选择值从''= " /''更改为''= "/confluence /''。 – jrummell 2010-06-18 15:15:09

相关问题