如何使用xslt格式化XML元素中的字符串

时间:2017-12-14 21:59:03

标签: html xml xslt soa osb

我有一个XML,其中一个元素包含连接的注释列表。我需要对其进行格式化并将其映射到目标xml节点。

输入XML元素值:

<Comment> TJ-TACO JOHNS Dented Cans - RFS# D2804 and D01441)Inspect entire load for dented cans.2)Pay close attention to hidden damage of dentedcans, specially towards the bottom cornersof pallet.3)If dented cans found,take pictures, rejectimplicated product & document in COMMENTS on PO.4)Report issue to buyer to notify vendor.5)Report issue to FSQA to notify Taco Johns QA. </Comment>

预期输出格式:

<Output>
TJ-TACO JOHNS Dented Cans - RFS# D2804 and D0144
1)Inspect entire load for dented cans.
2)Pay close attention to hidden damage of dentedcans, specially towards the bottom cornersof pallet.
3)If dented cans found,take pictures, reject implicated product & document in COMMENTS on PO.
4)Report issue to buyer to notify vendor.
5)Report issue to FSQA to notify Taco Johns QA.
</Output>

如何在xslt中实现这一目标?

1 个答案:

答案 0 :(得分:0)

试试这个:

 <xsl:template match="Comment">
    <Output>
        <xsl:analyze-string select="." regex="[0-9]\)">
            <xsl:matching-substring>
                <xsl:text>&#xA;</xsl:text><xsl:value-of select="regex-group(0)"></xsl:value-of>
            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:value-of select="."></xsl:value-of>
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </Output>
</xsl:template>

您可以在http://xsltransform.hikmatu.com/nbUY4ko

查看脚本

但您的问题中没有额外信息,因此仅适用于单位数