oursgris
oursgris

Reputation: 2882

Problem of compatibility with Saxon 9.2 he

I've a problem with a xslt file with saxon 9.2 he. (The xslt file works in xslt 1.0 with the engine included in c# but it is too slow)

The Xslt file

<?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>

the Xml source file

<?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>

The wanted output file

<?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>

But every time I use attributes inside Magasin or Client like @ComplementCodeRouteur it returns nothing. The only attribute which is working is Id={@Id} in Magasins. Does someone know why and how to resolve it ? I'm not good enough to find why it isn't working.

Upvotes: 0

Views: 371

Answers (2)

mzjn
mzjn

Reputation: 51082

This simplified stylesheet:

<?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>

produces this output:

$ 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>

which is what you wanted.

The alleged compatibility problem looks like a side issue. No XSLT processor will produce the wanted output using the stylesheet shown in the question. Therefore I suggest a different way to produce the output.

Upvotes: 1

Martin Honnen
Martin Honnen

Reputation: 167781

I tried to run your samples with Saxon 9.3.0.5 Java from the command line and the output is as follows:

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>

That looks fine to me (although it does some grouping you did not show in your posted sample). Does the .NET version you probably use really give you a different result? How do you run the transformation with .NET?

[edit] I have also now tried the .NET version of Saxon 9.3 from the command line, it too outputs

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>

Upvotes: 1

Related Questions