字符串长度约为120
这里是我的消息字符串: CID_Ultimate_Ben_Details = pabbisettishanmukhpraveenkumarpabbisettishanmukhpraveenkumarpabbisettishanmukhpraveenkumarpabbisettishanmukhpraveenkumar
例如:消息长度为140
输出所需的输出为:1 to 35 chars in first line
36 t0 70 chars in second line
71 to 105 chars in third line
106 to 140 in fourth line
这是我的xslt逻辑:
<xsl:if test ="./CID_Ultimate_Ben_Details != '' " >
<xsl:if test ="string-length(./CID_Ultimate_Ben_Details) != '11' and string-length(./CID_Ultimate_Ben_Details) != '8' ">
<xsl:if test="string-length(./CID_Ultimate_Ben_Details) > 1">
<xsl:value-of select="concat(':58D:',substring(./CID_Ultimate_Ben_Details,1,35))" />
</xsl:if>
<xsl:if test="string-length(./CID_Ultimate_Ben_Details) > 35">
<xsl:value-of select="concat(' ',substring(./CID_Ultimate_Ben_Details,36,70))" />
</xsl:if>
<xsl:if test="string-length(./CID_Ultimate_Ben_Details) > 70">
<xsl:value-of select="concat(' ',substring(./CID_Ultimate_Ben_Details,71,105))" />
</xsl:if>
<xsl:if test="string-length(./CID_Ultimate_Ben_Details) > 105">
<xsl:value-of select="concat(' ',substring(./CID_Ultimate_Ben_Details,106,140))" />
</xsl:if>
</xsl:if>
<xsl:text> </xsl:text >
</xsl:if>
输出要求为: 的:58D:pabbisettishanmukhpraveenkumarpabbi settishanmukhpraveenkumarpabbisetti shanmukhpraveenkumarpabbisettishanm ukhpraveenkumar
但是现在对于上面的逻辑输出就是这样:
:58D:pabbisettishanmukhpraveenkumarpabbi settishanmukhpraveenkumarpabbisettishanmukhpraveenkumarpabbisettishanm shanmukhpraveenkumarpabbisettishanmukhpraveenkumar ukhpraveenkumar
为什么它以无关的方式产生clrf。任何人都建议我取得我所需的输出
答案 0 :(得分:0)
这是一个正确的和通用的(适用于任何文本长度和数量的输出行)XSLT 1.0解决方案(XSLT 2.0解决方案非常简单):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pmsgLength" select="140"/>
<xsl:param name="pnumLines" select="4"/>
<xsl:variable name="vmaxLineLength" select=
"ceiling($pmsgLength div $pnumLines)"/>
<xsl:template match="/*/text()" name="split">
<xsl:param name="pText" select="."/>
<xsl:param name="pnextLines" select="$pnumLines"/>
<xsl:param name="pHead" select="':58D:'"/>
<xsl:if test="$pnextLines">
<xsl:value-of select=
"concat('
',$pHead, substring($pText, 1, $vmaxLineLength))"/>
<xsl:call-template name="split">
<xsl:with-param name="pText" select="substring($pText, $vmaxLineLength+1)"/>
<xsl:with-param name="pnextLines" select="$pnextLines -1"/>
<xsl:with-param name="pHead" select="''"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
将此转换应用于以下XML文档:
<t>pabbisettishanmukhpraveenkumarpabbisettishanmukhpraveenkumarpabbisettishanmukhpraveenkumarpabbisettishanmukhpraveenkumar</t>
生成所需的正确输出:
:58D:pabbisettishanmukhpraveenkumarpabbi
settishanmukhpraveenkumarpabbisetti
shanmukhpraveenkumarpabbisettishanm
ukhpraveenkumar
答案 1 :(得分:0)
substring()
的第三个参数是所需的长度,而不是Java中的结束位置。