xsl:排序缩进的副作用



>我需要根据属性 billOfMaterialItemID 的值对元素 BillOfMaterialIem 进行排序 例:

<?xml version="1.0" encoding="UTF-8"?>
<PackageData documentCreateDate="2019-10-03" documentModificationDate="2019-10-03">
<Items>
<Item itemID="416664">
<BillOfMaterial>
<BillOfMaterialItem billOfMaterialItemID="417230" />
<BillOfMaterialItem billOfMaterialItemID="417231" />
<BillOfMaterialItem billOfMaterialItemID="416664-01"/>
<BillOfMaterialItem billOfMaterialItemID="110424" />
</BillOfMaterial>
</Item>
</Items>
</PackageData>

可以复制所有内容并过滤空属性:

<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()">
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:if test="string-length(.)!=0">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>

以下是特定于元素 BillOfMaterial 的模板:

<xsl:template match="BillOfMaterial">
<xsl:copy>
<xsl:apply-templates select="BillOfMaterialItem" >
<xsl:sort select="@billOfMaterialItemID"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

元素按预期排序,但输出中的缩进被杀死 - 尽管 indent="yes"。 我不明白这种副作用的原因。

我错过了什么?

<xsl:strip-space elements="*"/> makes it work

谢谢你,迈克尔.hor257k

最新更新