问题
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=" "/>
</xsl:template>
来源:https://stackoverflow.com/questions/41742209/splitting-of-strings-based-on-the-required-length