[xslt] libxslt problem with an attribute's namespace if it is a defaultone?



Hi, I have a following xsl, that just creates some xml (does not depend on
the source xml):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format";>
<xsl:template match="/">
<root xmlns="urn:A" xmlns:b="urn:B" xmlns:a="urn:A">
 <Products>
  <Product a:ID="1001" a:Name="Engine">
	<Price b:Currency="euro">100000</Price>
  </Product>
  <Product a:ID="1002" a:Name="Tire">
        <Price b:Currency="euro">100</Price>
  </Product>
 </Products>
</root>
</xsl:template>
</xsl:stylesheet>

Now if I do the transformation with the xsl above, the libxslt gives
different output compared to that given by for example MSXML and Xalan
2.5.2.

Here is the output given by the libxslt:

<?xml version="1.0"?>
<root xmlns="urn:A" xmlns:b="urn:B" xmlns:a="urn:A"
xmlns:fo="http://www.w3.org/
1999/XSL/Format">
 <Products>
  <Product ID="1001" Name="Engine">
      <Price b:Currency="euro">100000</Price>
  </Product>
  <Product ID="1002" Name="Tire">
      <Price b:Currency="euro">100</Price>
  </Product>
 </Products>
</root>

and here the output given by the Xalan:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:fo="http://www.w3.org/1999/XSL/Format"; xmlns:a="urn:A"
xmlns:b="urn:B" xmlns="urn:A">
 <Products>
  <Product a:Name="Engine" a:ID="1001">
      <Price b:Currency="euro">100000</Price>
  </Product>
  <Product a:Name="Tire" a:ID="1002">
      <Price b:Currency="euro">100</Price>
  </Product>
 </Products>
</root>

You can notice from the libxslt's output that the namespace having prefix
"a" is not included into the attributes of Product element. This is the case
only if that namespace is also the default namespace. As you can see the
namespace having prefix b is attached to the correct attribute Currency.
Like said in the "Namespaces in XML" in
http://www.w3.org/TR/REC-xml-names/#defaulting the default namespace applies
to the element where it is declared and to all elements with no prefix
within the content of that element. That's why there is no need to prefix
for example Products-element if it is supposed to belong to the default
namespace. But that same rule cannot be applied to the attributes and said
again in the same chapter -> "default namespaces do not apply directly to
attributes" and also in Michael Kay's XSLT 2nd Edition -book, page 66, it is
said that if attribute name does not have any prefix then its namespace URI
is considered to be a null URI i.e. in my example the Name-attribute of the
Product-element does not belong to any namespace because there is no prefix
attached to it.

So if the application, that uses the result xml from libxslt, waits for an
attribute "Name" belonging to the urn:A namespace it will not recognize it
because of the lack of the prefix.

This problem, if using libxslt for transformation, can be passed by marking
every element belonging to the default namespace with the default
namespace's prefix and after that the libxslt produces a result where also
attributes have the default namespace's prefix, but that is a thing you
should not have to do according to the XML specs.

The xsltproc (and libxslt/libxml) I have used to produce the result xml are
following:

$ xsltproc --version
Using libxml 20605, libxslt 10102 and libexslt 802
xsltproc was compiled against libxml 20605, libxslt 10102 and libexslt 802
libxslt 10102 was compiled against libxml 20605
libexslt 802 was compiled against libxml 20605

- Markku Nykky



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]