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

How to format string in XML element using xslt

我有一个 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 中实现这一点?

试试这个:

 <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

查看脚本

但是你的问题中没有额外的信息,所以这只适用于个位数