Splitting of strings based on the required length

天涯浪子 提交于 2019-12-24 05:46:31

问题


Is there an easy way on how to split a string based from the required length? For example, I have a string:

<Data>AAAAABBBBB1111122222RRRRR<Data>

and I want to populate an output like this:

AAAAA
BBBBB
11111
22222
RRRRR

Thank you.


回答1:


You can use analyze-string to break up the data:

<xsl:template match="Data">
    <xsl:variable name="tokens" as="xs:string*">
        <xsl:analyze-string select="." regex=".{{1,5}}">
            <xsl:matching-substring>
                <xsl:sequence select="."/>
            </xsl:matching-substring>
        </xsl:analyze-string>
    </xsl:variable>
    <xsl:value-of select="$tokens" separator="&#10;"/>
</xsl:template>


来源:https://stackoverflow.com/questions/41742209/splitting-of-strings-based-on-the-required-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!