我需要使用xsl将长文本字段分成一个或多个重复项,其中包含具有定义长度(即50 ch)的长文本的一部分。 输入示例:
....
的< LONGTEXT>
Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是业界标准的虚拟文本,当时一台未知的打印机采用了类型的厨房,并将其拼凑成一个类型的样本书。
< / LONGTEXT>
....
我期待以下输出:
....
的< pieceOfLongTextElement>
<步骤→1< /步骤>
< text> Lorem Ipsum只是打印的虚拟文本< / text>
< / pieceOfLongTextElement>
< pieceOfLongTextElement>
<步骤> 2'; /步骤>
< text>排版行业。 Lorem Ipsum一直是< / text>
< / pieceOfLongTextElement>
所以直到达到长文本长度,从50增加到50个字符...
感谢。
答案 0 :(得分:2)
假设您可以使用XSLT 2.0,您只需使用xsl:analyze-string
分解字符串:
<xsl:template match="longText">
<xsl:analyze-string select="." regex=".{{1,50}}">
<xsl:matching-substring>
<piece step="{position()}">
<xsl:value-of select="."/>
</piece>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
请参阅http://xsltransform.net/pPJ8LWa/1哪些输出
<piece step="1">Lorem Ipsum is simply dummy text of the printing a</piece>
<piece step="2">nd typesetting industry. Lorem Ipsum has been the </piece>
<piece step="3">industry's standard dummy text ever since the 1500</piece>
<piece step="4">s, when an unknown printer took a galley of type a</piece>
<piece step="5">nd scrambled it to make a type specimen book.</piece>