我有以下XSLT宏(在Umbraco中)
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:apply-templates select="$currentPage/imageList/multi-url-picker" />
</xsl:template>
<xsl:template match="url-picker">
<xsl:variable name="url"><xsl:value-of select="./url" /></xsl:variable>
<xsl:value-of select="concat('"', $url, '",')" />
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
我想不要将逗号添加到集合中的最后一个url-picker.我该怎么做呢?
编辑: XML架构,仅供参考:
<multi-url-picker>
<url-picker mode="URL">
<new-window>True</new-window>
<node-id />
<url>http://our.umbraco.org</url>
<link-title />
</url-picker>
<url-picker mode="Content">
<new-window>False</new-window>
<node-id>1047</node-id>
<url>/homeorawaytest2.aspx</url>
<link-title />
</url-picker>
<url-picker mode="Media">
<new-window>False</new-window>
<node-id>1082</node-id>
<url>/media/179/bolero.mid</url>
<link-title>Listen to this!</link-title>
</url-picker>
<url-picker mode="Upload">
<new-window>False</new-window>
<node-id />
<url>/media/273/slide_temp.jpg</url>
<link-title />
</url-picker>
Run Code Online (Sandbox Code Playgroud)
用途:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="url">
<xsl:if test="not(position()=1)">
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:value-of select="concat('"', ., '"')" />
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
当应用于此XML文档时(没有提供!):
<url-picker>
<url>1</url>
<url>2</url>
<url>3</url>
</url-picker>
Run Code Online (Sandbox Code Playgroud)
产生了想要的正确结果:
"1","2","3"
Run Code Online (Sandbox Code Playgroud)
请注意:
你不需要变量$url.
如果您需要这样的变量,请永远不要创建子节点(这会导致RTF).始终使用以下select属性xsl:variable:
而不是:
<xsl:variable name="url"><xsl:value-of select="./url" /></xsl:variable>
Run Code Online (Sandbox Code Playgroud)
写道:
<xsl:variable name="url" select="url" />
Run Code Online (Sandbox Code Playgroud)
0.3.对变量使用某种命名约定是一种很好的做法,因此如果$意外跳过该名称,则名称将不会轻易与现有元素的名称相同.例如使用:
<xsl:variable name="vUrl" select="url" />
Run Code Online (Sandbox Code Playgroud)