I have a string like
*this is text1 * this is text2 *this is text3
I want the output by spliting the text using * in my pdf like
this is text1
this is text2
this is text3
my text coming in @value of xslt like
<fo:block linefeed-treatment="preserve" >
<xsl:value-of select="@key"/>
</fo:block>
<fo:block linefeed-treatment="preserve" >
<xsl:value-of select="@value"/>
</fo:block>
<fo:block linefeed-treatment="preserve" >
<xsl:text>
</xsl:text>
</fo:block>
</fo:block>
How can I split the string produce the output. Please suggest. I'm using xsl 1.0
First call a template which performs the splitting for you instead of the value-of
:
<xsl:call-template name="split">
<xsl:with-param name="text" select="@value"/>
</xsl:call-template>
Here is the named template:
<xsl:template name="split">
<xsl:param name="text" select="."/>
<xsl:if test="string-length($text) > 0">
<xsl:variable name="output-text">
<xsl:value-of select="normalize-space(substring-before(concat($text, '*'), '*'))"/>
</xsl:variable>
<xsl:if test="normalize-space($output-text) != ''">
<xsl:value-of select="$output-text"/>
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:call-template name="split">
<xsl:with-param name="text" select="substring-after($text, '*')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Input (value of the @value
):
*this is text1 * this is text2 *this is text3
Output:
this is text1
this is text2
this is text3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.