2011-08-17 14 views
0

我與薩克森9.2他xslt文件存在問題。 (XSLT文件工作在XSLT 1.0與包含在C#中的發動機,但它是太慢)與薩克森9.2兼容性問題他他

XSLT文件

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="Magasins"> 
    <Magasins xmlns:xi="http://www.w3.org/2001/XInclude" Id="{@Id}"> 
     <xsl:apply-templates/> 
    </Magasins> 
    </xsl:template> 

    <xsl:key name="kClientGroup" match="Client" 
     use="concat(../@CodeRouteur, @ComplementCodeRouteur)" 
     /> 

    <xsl:template match="Magasin"> 
<xsl:apply-templates select="Client[generate-id() 
     = 
     generate-id(key('kClientGroup', 
     concat(../@CodeRouteur, @ComplementCodeRouteur))[1])]" 
     /> 
    </xsl:template> 

    <xsl:template match="Client"> 
    <Magasin 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     CodeRouteur="{concat(../@CodeRouteur,@ComplementCodeRouteur)}"> 

     <xsl:copy-of select="../@*[name() != 'CodeRouteur']"/> 

     <xsl:apply-templates select="key('kClientGroup', 
       concat(../@CodeRouteur,@ComplementCodeRouteur))" mode="copy"/> 

    </Magasin> 
    </xsl:template> 

    <xsl:template match="Client" mode="copy"> 
    <xsl:copy> 
     <xsl:copy-of select="node()|@*"/> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

XML源文件

<?xml version="1.0" encoding="UTF-8"?> 
<Magasins> 
    <Magasin Nom="Name" CodeRouteur="TE"> 
    <Client IdClient="1" ComplementCodeRouteur="A" Name="YYY"><Elem /></Client> 
    <Client IdClient="2" ComplementCodeRouteur="B" Name="XXX"><Elem /></Client> 
    </Magasin> 
    <Magasin Nom="Name2" CodeRouteur="TE"> 
    <Client IdClient="3" ComplementCodeRouteur="A" Name="YYY"><Elem /></Client> 
    </Magasin> 
</Magasins> 

想要的輸出文件

<?xml version="1.0" encoding="UTF-8"?> 
<Magasins> 
    <Magasin Nom="Name" CodeRouteur="TEA"> 
    <Client IdClient="1" ComplementCodeRouteur="A" Name="YYY"><Elem /></Client> 
    </Magasin> 
    <Magasin Nom="Name" CodeRouteur="TEB"> 
    <Client IdClient="2" ComplementCodeRouteur="B" Name="XXX"><Elem /></Client> 
    </Magasin> 
    <Magasin Nom="Name2" CodeRouteur="TEA"> 
    <Client IdClient="3" ComplementCodeRouteur="A" Name="YYY"><Elem /></Client> 
    </Magasin> 
</Magasins> 

但是,每當我使用@ComplementCodeRouteur的Magasin或Client內部的屬性時,它都不會返回任何內容。 Magasins中唯一的工作屬性是Id = {@ Id}。 有人知道爲什麼以及如何解決它? 我不夠好找到它不工作的原因。

回答

1

我試圖在命令行中運行帶有撒克遜9.3.0.5的Java您的樣品和輸出如下:

Warning: at xsl:stylesheet on line 2 column 81 of test2011081702.xsl: 
    Running an XSLT 1 stylesheet with an XSLT 2 processor 
<?xml version="1.0" encoding="UTF-8"?> 
<Magasins xmlns:xi="http://www.w3.org/2001/XInclude" Id=""> 
    <Magasin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      CodeRouteur="TEA" 
      Nom="Name"> 
     <Client IdClient="1" ComplementCodeRouteur="A" Name="YYY"> 
     <Elem/> 
     </Client> 
     <Client IdClient="3" ComplementCodeRouteur="A" Name="YYY"> 
     <Elem/> 
     </Client> 
    </Magasin> 
    <Magasin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      CodeRouteur="TEB" 
      Nom="Name"> 
     <Client IdClient="2" ComplementCodeRouteur="B" Name="XXX"> 
     <Elem/> 
     </Client> 
    </Magasin> 

</Magasins> 

這看起來好像沒什麼問題(儘管它的一些分組你沒有表現出您發佈的示例)。你可能使用的.NET版本是否真的給你一個不同的結果?你如何運行.NET的轉換?

[編輯]我現在也通過命令行試圖撒克遜9.3的.NET版本,它也輸出

Warning: at xsl:stylesheet on line 2 column 81 of test2011081702.xsl: 
    Running an XSLT 1 stylesheet with an XSLT 2 processor 
<?xml version="1.0" encoding="UTF-8"?> 
<Magasins xmlns:xi="http://www.w3.org/2001/XInclude" Id=""> 
    <Magasin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      CodeRouteur="TEA" 
      Nom="Name"> 
     <Client IdClient="1" ComplementCodeRouteur="A" Name="YYY"> 
     <Elem/> 
     </Client> 
     <Client IdClient="3" ComplementCodeRouteur="A" Name="YYY"> 
     <Elem/> 
     </Client> 
    </Magasin> 
    <Magasin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      CodeRouteur="TEB" 
      Nom="Name"> 
     <Client IdClient="2" ComplementCodeRouteur="B" Name="XXX"> 
     <Elem/> 
     </Client> 
    </Magasin> 

</Magasins> 
1

這種簡化的樣式表:

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="/"> 
    <Magasins> 
     <xsl:apply-templates/> 
    </Magasins> 
    </xsl:template> 

    <xsl:template match="Magasin"> 
    <xsl:apply-templates select="Client"/> 
    </xsl:template> 

    <xsl:template match="Client"> 
    <Magasin Nom="{../@Nom}" 
     CodeRouteur="{concat(../@CodeRouteur,@ComplementCodeRouteur)}"> 
     <xsl:apply-templates select="." mode="copy"/> 
    </Magasin> 
    </xsl:template> 

    <xsl:template match="*" mode="copy"> 
    <xsl:copy> 
     <xsl:copy-of select="node()|@*"/> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

產生以下輸出:

$ java -jar c:/Java/saxon92/saxon9he.jar magasin.xml magasin2.xsl 
Warning: at xsl:stylesheet on line 2 column 81 of magasin2.xsl: 
    Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor 
<?xml version="1.0" encoding="UTF-8"?> 
<Magasins> 
    <Magasin Nom="Name" CodeRouteur="TEA"> 
     <Client IdClient="1" ComplementCodeRouteur="A" Name="YYY"> 
     <Elem/> 
     </Client> 
    </Magasin> 
    <Magasin Nom="Name" CodeRouteur="TEB"> 
     <Client IdClient="2" ComplementCodeRouteur="B" Name="XXX"> 
     <Elem/> 
     </Client> 
    </Magasin> 
    <Magasin Nom="Name2" CodeRouteur="TEA"> 
     <Client IdClient="3" ComplementCodeRouteur="A" Name="YYY"> 
     <Elem/> 
     </Client> 
    </Magasin> 
</Magasins> 

這就是你想要的。

所謂的兼容性問題看起來像是一個側面問題。沒有XSLT處理器會使用問題中顯示的樣式表產生所需的輸出。因此,我建議採用不同的方式來生產產出。