Splitting of strings based on the required length

2019-09-14 01:38发布

问题:

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>