I have a xsl parameter which a string. I want to parse that string, split it and for each substring value I want to apply the templa开发者_StackOverflowte in the xsl.
Is this possible? If so, Can you please advise an optimistic solution?
Thanks
Edit: Missundertood the question, sorry.
The answer is yes.
Input:
<secuence>Item1 Item2 Item3</secuence>
Stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="secuence/text()" name="secuence">
<xsl:param name="string" select="."/>
<xsl:param name="separator" select="' '"/>
<xsl:if test="$string != ''">
<xsl:choose>
<xsl:when test="contains($string,$separator)">
<xsl:call-template name="secuence">
<xsl:with-param name="string" select="substring-before($string,$separator)"/>
<xsl:with-param name="separator" select="$separator"/>
</xsl:call-template>
<xsl:call-template name="secuence">
<xsl:with-param name="string" select="substring-after($string,$separator)"/>
<xsl:with-param name="separator" select="$separator"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- Your desired template -->
<Item>
<xsl:value-of select="$string"/>
</Item>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Result:
<secuence>
<Item>Item1</Item>
<Item>Item2</Item>
<Item>Item3</Item>
</secuence>
Unsure what you mean but copying this pattern may help: XSLT - Best way to split and render comma separated text as HTML
精彩评论