在XML文件中有个属性保存了n个图像名,在XSL怎么写,使这n个图片依次显示出来?

OnlyVB 2010-10-15 09:43:45
在XML文件中有个属性保存了n个图像名,在XSL怎么写,使这n个图片依次显示出来?

属性值类似:a.jpg,b.jpg,c.jpg,d.jpg,e.jpg,f.jpg,……

想用循环,不知道循环怎么写?

请各位说说有啥好办法?
...全文
129 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
拷贝
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ',')" />
<xsl:variable name="first" select="substring-before($newlist, ',')" />
<xsl:variable name="remaining" select="substring-after($newlist, ',')" />
<img src="{$first}" />
<xsl:if test="substring-before($remaining, ',') != ''">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>


调用方法

<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$Img"/>
</xsl:call-template>
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
这样
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$Img"/>
</xsl:call-template>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/root">
<xsl:variable name="Img">
<xsl:value-of select="@name"/>
</xsl:variable>
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$Img"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ',')" />
<xsl:variable name="first" select="substring-before($newlist, ',')" />
<xsl:variable name="remaining" select="substring-after($newlist, ',')" />
<img src="{$first}" />
<xsl:if test="substring-before($remaining, ',') != ''">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />
</xsl:call-template>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
OnlyVB 2010-10-15
  • 打赏
  • 举报
回复
类似TreeMenu/Images/SubNodeImg1.gif, TreeMenu/Images/SubNodeImg1.gif
等等,不确定
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
你的$Img是字符串吗?值是多少?
OnlyVB 2010-10-15
  • 打赏
  • 举报
回复
xsl原文件
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://dotnet.aspx.cc/" exclude-result-prefixes="user">
<xsl:variable name="LeafImgSrc">TreeMenu/Images/SubNodeImg1.gif</xsl:variable>
<xsl:variable name="BranchImgSrc">TreeMenu/Images/NodeImg1.gif</xsl:variable>
<xsl:variable name="FolderImgSrc">TreeMenu/Images/Folder.gif</xsl:variable>
<xsl:variable name="FileImgSrc">TreeMenu/Images/File.gif</xsl:variable>
<xsl:variable name="LineImgSrc">TreeMenu/Images/PreLine.gif</xsl:variable>
<xsl:variable name="LastSubNodeImgSrc">TreeMenu/Images/SubNodeImg2.gif</xsl:variable>
<xsl:variable name="LastNodeImgSrc">TreeMenu/Images/NodeImg2.gif</xsl:variable>
<xsl:variable name="FirstNodeImgSrc">TreeMenu/Images/NodeImg0.gif</xsl:variable>
<xsl:variable name="LastNodeSubNodeImgSrc">TreeMenu/Images/Blank.gif</xsl:variable>

<msxsl:script language="JavaScript" implements-prefix="user">
<![CDATA[
function showImg(nodelist) {
s = nodelist.split(",")
x =""
for(i = 0;i<s.length;i++)
{
x+="<img src='"+s[i]+"' >"
}
return x;
}
]]>
</msxsl:script>
<!--根目录循环-->
<xsl:template match="/">
<xsl:for-each select="ROOT/*">
<xsl:apply-templates select=".">
<!--获得图片名称-->
<xsl:with-param name="Img">
<xsl:choose>
<xsl:when test="position()=last()">
<xsl:value-of select="$LastSubNodeImgSrc" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$LeafImgSrc" />
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>

<!--非根目录循环-->
<xsl:template match="*">

<xsl:param name="Img"/>
<div class="clsItem" type="branch" style="white-space:nowrap">
<!--********要把下面这句显示成图片,而不是图片名-->
<xsl:value-of select="$Img"/>
<span class="clsLabel" type="label" onclick="MouseClick(this)" onmousedown="NodeMouseDown(this);" onmouseover="NodeMouseOver(this);" onmouseout="NodeMouseOut(this);" >
<xsl:value-of select="@TEXT"/>
</span>
</div>
<xsl:for-each select="*">
<xsl:apply-templates select=".">
<!--获得图片名称-->
<xsl:with-param name="Img">
<xsl:value-of select="$Img"/>,
<xsl:choose>
<xsl:when test="position()=last()">
<xsl:value-of select="$LastSubNodeImgSrc" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$LeafImgSrc" />
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>



把这句<xsl:value-of select="$Img"/>换成<xsl:value-of select="user:showImg($Img)"/>
出错呀,请老大再帮看看
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://dotnet.aspx.cc/" exclude-result-prefixes="user">
<msxsl:script language="JavaScript" implements-prefix="user">
<![CDATA[
function showImg(nodelist) {
s = nodelist.split(",")
x =""
for(i = 0;i<s.length;i++)
{
x+="<img src='"+s[i]+"' >"
}
return x;
}
]]>
</msxsl:script>
<xsl:template match="/root">
<xsl:variable name="Img">
<xsl:value-of select="str:split(@name)"/>
</xsl:variable>
<xsl:value-of select="user:showImg($Img)"/>
</xsl:template>
</xsl:stylesheet>
OnlyVB 2010-10-15
  • 打赏
  • 举报
回复
多谢楼上!
//img是什么意思呀?
其实这个值a.jpg,b.jpg,c.jpg,d.jpg,e.jpg,f.jpg,……是在xsl文件中生成的,保存在name=Img中

用<xsl:value-of select="$Img"/>可以显示出来图片路径及名称

<xsl:for-each select="//img">
<img><xsl:attribute name="src"><xsl:value-of select="."/></xsl:attribute></img>
</xsl:for-each>

//img替换成啥呀
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
也可以
<xsl:for-each select="//img">
<img><xsl:attribute name="src"><xsl:value-of select="."/></xsl:attribute></img>
</xsl:for-each>

孟子E章 2010-10-15
  • 打赏
  • 举报
回复
<xsl:for-each select="//img">
<img src="{.}" />
</xsl:for-each>

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧