HTML链接及其描述的XSL分隔值
我试图调试一些xsl代码,这些代码将从XML文档收集的链接及其描述放在一个列表中,它似乎可以工作,但处理从单个字符串收集的多个链接时除外,该字符串用“|”和“^”符号分隔 包含此代码的XML行与此非常相似:HTML链接及其描述的XSL分隔值,html,xml,api,xslt,asp-classic,Html,Xml,Api,Xslt,Asp Classic,我试图调试一些xsl代码,这些代码将从XML文档收集的链接及其描述放在一个列表中,它似乎可以工作,但处理从单个字符串收集的多个链接时除外,该字符串用“|”和“^”符号分隔 包含此代码的XML行与此非常相似: <WebContent> <content_type_desc>Links</content_type_desc> <content_value>Google|http://www.google.com^Yahoo|htt
<WebContent>
<content_type_desc>Links</content_type_desc>
<content_value>Google|http://www.google.com^Yahoo|http://www.yahoo.com^Bing|Http://www.bing.com</content_value>
</WebContent>
链接
谷歌|http://www.google.com^雅虎|http://www.yahoo.com^Bing|Http://www.bing.com
处理此问题的xsl如下所示
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<!--Links-->
<xsl:variable name="links" select="//WebContent[content_type_desc='Links']/content_value "/>
<!--Links-->
<!--Links section-->
<xsl:if test="$links != ''">
<br />
<xsl:choose>
<xsl:when test="contains($links,'^')">
<xsl:variable name="URL" select="substring-after(substring-before($links,'^'),'|')"/>
<xsl:variable name="URLText" select="substring-before($links,'|')"/>
<strong>Links: </strong><br />
<a href="$URL" target="_blank"><xsl:value-of select="$URLText"/></a>
<br />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="URL" select="substring-after($links,'|')"/>
<xsl:variable name="URLText" select="substring-before($links,'|')"/>
<strong>Links: </strong><br />
<a href="{$URL}" target="_blank"><xsl:value-of select="$URLText"/></a>
<br />
</xsl:otherwise>
</xsl:choose>
<br />
</xsl:if>
<!--Links section-->
</xsl:template>
</xsl:stylesheet>
链接:
链接:
问题是它只输出
<a href="http://www.google.com>Google</a>
我希望它什么时候输出
<a href="http://www.google.com>Google</a>
<a href="http://www.yahoo.com>Yahoo</a>
<a href="http://www.bing.com>Bing</a>
任何帮助都将不胜感激,因为我完全被难住了。鉴于您已将问题标记为经典ASP,您的XSLT处理器可能是MSXML的某个版本,因此您可以使用该版本。假设您实际上只使用XSLT 1.0,要解决这个问题,可以使用递归调用的命名模板 目前,代码只处理代码中第一个
^
之前的URL。您可以做的是将检查链接的大部分代码放入命名模板中。然后,在URL确实包含^
时运行的xsl:when条件中,向命名模板添加递归调用,但只在^
之后传递子字符串
试试这个XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<xsl:param name="links" select="//WebContent[content_type_desc='Links']/content_value "/>
<xsl:if test="$links != ''">
<strong>Links: </strong>
<br />
<xsl:call-template name="splitlinks">
<xsl:with-param name="links" select="$links" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="splitlinks">
<xsl:param name="links" />
<xsl:choose>
<xsl:when test="contains($links,'^')">
<xsl:variable name="URL" select="substring-after(substring-before($links,'^'),'|')"/>
<xsl:variable name="URLText" select="substring-before($links,'|')"/>
<a href="{$URL}" target="_blank"><xsl:value-of select="$URLText"/></a>
<br />
<xsl:call-template name="splitlinks">
<xsl:with-param name="links" select="substring-after($links,'^')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="URL" select="substring-after($links,'|')"/>
<xsl:variable name="URLText" select="substring-before($links,'|')"/>
<a href="{$URL}" target="_blank"><xsl:value-of select="$URLText"/></a>
<br />
</xsl:otherwise>
</xsl:choose>
<br />
</xsl:template>
</xsl:stylesheet>
链接: