2011-08-17 12 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处理器会使用问题中显示的样式表产生所需的输出。因此,我建议采用不同的方式来生产产出。