【发布时间】:2010-12-23 20:15:07
【问题描述】:
我不是 XSL 专家,我在为简单的逻辑而苦恼:
我有一个值为“A,B,C”的 XSL 变量,想将其拆分并将各个值存储到三个不同的 XSL 变量中,例如
X=A
Y= B
Z=C
但有时它可能只有一个/两个值或没有值...
如果它只有一个值,那么变量值应该是这样的
X=A
Y=
Z=
如果它没有任何价值,那么
X=
Y=
Z=
请帮助我提供相同的 XSL 代码
让我们说:
Tags 的值为“Test,Demo,Sample”然后我想像这样拆分
<xsl:choose>
<xsl:when test="contains($Tags,',')">
<xsl:variable name="Tags1">
<xsl:value-of select="substring-before($Tags,',')" />
</xsl:variable>
<xsl:variable name="ATag1">
<xsl:value-of select="substring-after($Tags,',')" />
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="Tags1"/>
<xsl:variable name="ATags1"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="contains($ATags1,',')">
<xsl:variable name="Tags2">
<xsl:value-of select="substring-before($ATags1,',')" />
</xsl:variable>
<xsl:variable name="ATag2">
<xsl:value-of select="substring-after($ATags1,',')" />
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="Tags2"/>
<xsl:variable name="ATags2"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="contains($ATags2,',')">
<xsl:variable name="Tags3">
<xsl:value-of select="substring-before($ATags2,',')" />
</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="Tags3"/>
</xsl:otherwise>
</xsl:choose>
但它对我不起作用......
【问题讨论】:
-
你需要一个 split 函数,但 xslt 中似乎没有一个 - 所以使用这里描述的一个:stackoverflow.com/questions/136500/…