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
我想要输出,在我的pdf文件中使用*分割文本
this is text1
this is text2
this is text3
my text coming in @value of xslt like
我的文本以@value的形式出现。
<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
如何分割字符串生成输出。请建议。我使用xsl 1.0
1 个解决方案
#1
4
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
):
输入(@value的值):
*this is text1 * this is text2 *this is text3
Output:
输出:
this is text1
this is text2
this is text3
#1
4
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
):
输入(@value的值):
*this is text1 * this is text2 *this is text3
Output:
输出:
this is text1
this is text2
this is text3