2011-08-08 6 views
2

イムで空の属性を削除し、その後、IVEは働いてしまった、属性、しかし、私はどのようにここですべての要素をソートするためにしようとXSLT

空の属性を削除するには、ソートXSLT

である私の人生のために把握カント
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 

<xsl:output method="xml" indent="yes"/> 

<xsl:template match="@* | node()"> 
    <xsl:copy> 

     <xsl:apply-templates > 
      <xsl:sort select="local-name()"/> 
     </xsl:apply-templates> 

    </xsl:copy> 
</xsl:template> 


<xsl:template match="*[*]"> 

    <xsl:copy> 
     <xsl:apply-templates select="@*" > 
      <xsl:sort select="local-name()" /> 
     </xsl:apply-templates> 

     <xsl:apply-templates select="*" > 
      <xsl:sort select="local-name()"/> 
     </xsl:apply-templates> 

    </xsl:copy> 
</xsl:template> 

任意のヘルプ

+0

属性はXMLでは順序がありませんので、順序は常に期待どおりです。 – Lucero

+0

アルファベット順のソート順ではなく、インデックス位置にintrestされていない –

+0

ポイントは、変換先(XmlWriter実装など)によっては、書き込まれる属性の順序が必ずしもその順序に一致する必要はありませんあなたが指定しています。私はあなたにこの事実を知らせるだけです。 – Lucero

答えて

3

まあのおかげであなたは属性ノードを処理する唯一の場所はとてもにあることを変更<xsl:apply-templates select="@*">ですで十分でしょう。

1
<xsl:template match="@*"> 
    <xsl:if test="string-length(.)!=0"> 
     <xsl:copy /> 
    </xsl:if> 
</xsl:template> 

<xsl:template match="node()"> <!-- replaces the "match='@* | node()'" template --> 
    <xsl:copy> 
     <xsl:apply-templates > 
      <xsl:sort select="local-name()"/> 
     </xsl:apply-templates> 
    </xsl:copy> 
</xsl:template> 
+0

私は以前にこれに似た何かをしました。しかし、私は 'string-length'を使用していませんでした。 –

関連する問題