使用 CDATA 元素对 xml 中的 uuid 进行排序的 xslt 模板

问题描述

我有一个 xslt 模板,用于对同一文件中的 uuid 进行排序。

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ae="http://www.test.com/ae/types/2009">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" cdata-section-elements="ae:uuid ae:timeZoneId ae:stringId ae:name" standalone="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="uuids">
    <xsl:copy>
        <xsl:apply-templates select="uuid">
            <xsl:sort select="."/>
        </xsl:apply-templates>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>

这是我要解析的 xml 文件,这是大型 xml 文件,我正在复制 xml 文件的根目录,其中包含命名空间和使用 CDATA 修改的元素。

解决方法

如果输入没有 <xsl:template match="uuids"> 元素,

uuids 没有任何意义。

至于当前示例 cdata-section-elements="ae:value" 将修复 <value><![CDATA[AMNT Get test ]]></value> 元素,但由于您也有 a:value,其中您有不同的前缀但相同的命名空间我认为 XSLT 输出属性将使您能够区分它们,如果这是您想要的。