xsl-list
[Top] [All Lists]

Re: [xsl] Was it a bug?

2010-11-17 05:48:48
In XSLT 1.0, processors are allowed to invent namespace prefixes pretty well whenever they feel like it, so this is not a non-conformance.

Note, however, that the versions of Xerces and Xalan in the JDK are not simply earlier versions of the Apache products, they are effectively forks, and they have a reputation for bugginess. Use the Apache products in preference: they appear to have been much more carefully tested.

If you're in the Java world, however, there's very rarely a good reason to still be using XSLT 1.0.

Michael Kay
Saxonica

On 17/11/2010 11:27, Frederic Bergeron wrote:
Hi,

I have the following XML input file:

<lom xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"; 
xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM http://ltsc.ieee.org/xsd/lomv1.0/lom.xsd"; 
xmlns="http://ltsc.ieee.org/xsd/LOM";>
</lom>

And the following XSLT transformation file:

<xsl:stylesheet version="1.0"
     xmlns:lom="http://ltsc.ieee.org/xsd/LOM";
     xmlns="http://www.imsglobal.org/xsd/lodeilox_v1p0/digital_LO";
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     xmlns:xml="http://www.w3.org/XML/1998/namespace";
     exclude-result-prefixes="lom">
     <xsl:output method="xml" indent="yes"/>

     <xsl:template match="lom:lom" mode="work-description-main-metadata">
         <xsl:element name="{local-name()}" namespace="http://www.mystuff.com";>
             <xsl:attribute name="myatt">myval</xsl:attribute>
             <xsl:apply-templates/>
         </xsl:element>
     </xsl:template>

     <xsl:template match="*" mode="work-description-main-metadata">
       <xsl:element name="{local-name()}" namespace="http://www.mystuff.com";>
          <xsl:copy-of select="@*"/>
          <xsl:apply-templates select="*|text()"/>
       </xsl:element>
    </xsl:template>

     <xsl:template match="lom:lom">
         <xsl:element name="work">
             <xsl:attribute 
name="xsi:schemaLocation">http://www.imsglobal.org/xsd/lodeilox_v1p0/digital_LO 
http://www.imsglobal.org/xsd/imsloilox_v1p0_ilox_work_v1p0.xsd</xsl:attribute>
             <xsl:element name="identifier">myidentifier</xsl:element>
             <xsl:element name="description">
                 <xsl:element name="metadata">
                     <xsl:element 
name="schema">http://ltsc.ieee.org/xsd/LOM/imslode/ilox/work/main</xsl:element>
                     <xsl:apply-templates select="self::*" 
mode="work-description-main-metadata"/>
                 </xsl:element>
             </xsl:element>
         </xsl:element>
     </xsl:template>

</xsl:stylesheet>

When I use Xalan 2.6.0 (the default XSLT processor of the JRE 1.6.0_21-b07, if 
I'm not mistaken), I get the following output:

<work xmlns="http://www.imsglobal.org/xsd/lodeilox_v1p0/digital_LO"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://www.imsglobal.org/xsd/lodeilox_v1p0/digital_LO 
http://www.imsglobal.org/xsd/imsloilox_v1p0_ilox_work_v1p0.xsd";>
<identifier>myidentifier</identifier>
<description>
<metadata>
<schema>http://ltsc.ieee.org/xsd/LOM/imslode/ilox/work/main</schema>
<ns0:lom xmlns:ns0="http://www.mystuff.com"; myatt="myval">
</ns0:lom>
</metadata>
</description>
</work>

When I use Saxon 8.7 or Xalan 2.7.0, I get the following output:

<work xmlns="http://www.imsglobal.org/xsd/lodeilox_v1p0/digital_LO"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://www.imsglobal.org/xsd/lodeilox_v1p0/digital_LO 
http://www.imsglobal.org/xsd/imsloilox_v1p0_ilox_work_v1p0.xsd";>
<identifier>myidentifier</identifier>
<description>
<metadata>
<schema>http://ltsc.ieee.org/xsd/LOM/imslode/ilox/work/main</schema>
<lom xmlns="http://www.mystuff.com"; myatt="myval">
</lom>
</metadata>
</description>
</work>

Why, in the first case, do I have a generated prefix ns0 for the lom element 
and that I don't have one in the second case?  Was it a bug in the oldest 
version of Xalan?  Or is my XSLT ambiguous?

Regards,

Frederic Bergeron



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>