[英]How to split and break string in new line in XSLT
我有一个像
*this is text1 * this is text2 *this is text3
我想通过在我的pdf中使用*分割文本来输出
this is text1
this is text2
this is text3
我的文本在xslt的@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>
我如何分割字符串产生输出。 请提出建议。 我正在使用xsl 1.0
首先调用一个模板,该模板为您执行分割,而不是value-of
:
<xsl:call-template name="split">
<xsl:with-param name="text" select="@value"/>
</xsl:call-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>
输入( @value
值):
*this is text1 * this is text2 *this is text3
输出:
this is text1
this is text2
this is text3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.