Project

Profile

Help

Extra xmlns attributes being added to children elements - Java Saxon-EE 11.3

Added by Cory Madden almost 2 years ago

Hi There,

I have noticed that with Saxon 11.3 adds extra namespace attributes to the children elements when using xsl:mode. XSL

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" 
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:xs="http://www.w3.org/2001/XMLSchema"
				xmlns:ou="http://omniupdate.com/XSL/Variables"
				xmlns:fn="http://omniupdate.com/XSL/Functions"
				xmlns:ouc="http://omniupdate.com/XSL/Variables"
				exclude-result-prefixes="xsl xs ou fn ouc">

	<xsl:output method="html" version="5.0" indent="yes" encoding="UTF-8" />
	
	<xsl:mode on-no-match="shallow-copy" />

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

	<xsl:template match="/document">
		<html>
			<body>
				<xsl:apply-templates select="ouc:div[@label='mylabel']" /> 
			</body>
		</html>
	</xsl:template>

</xsl:stylesheet>

XML

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:ouc="http://omniupdate.com/XSL/Variables">
	<ouc:div label="mylabel" group="Everyone">
		<div class="item-9">
			<h1>This should output</h1>
		</div>
	</ouc:div>
</document>

The problem

The xmlns:ouc="http://omniupdate.com/XSL/Variables" is being added to the

. My understand is <xsl:mode on-no-match="shallow-copy" /> should not copy across the xmlns attributes If I have to change how I write this this, that is alright but how or this a bug? This did not do this in Saxon 9.7.

Replies (6)

Please register to reply

RE: Extra xmlns attributes being added to children elements - Java Saxon-EE 11.3 - Added by Cory Madden almost 2 years ago

Correcting my statement:

The xmlns:ouc="http://omniupdate.com/XSL/Variables" is being added to the first child div

RE: Extra xmlns attributes being added to children elements - Java Saxon-EE 11.3 - Added by Martin Honnen almost 2 years ago

xsl:mode on-no-match="shallow-copy" does an identity transformation where in scope namespace nodes are copied too, so the xmlns:ouc="..." which is in scope from the ancestor declaration is output on the div child correctly, by the serializer, in my view, as no ancestor was copied.

RE: Extra xmlns attributes being added to children elements - Java Saxon-EE 11.3 - Added by Michael Kay almost 2 years ago

Saxon's output here is definitely correct: shallow copy of an element, whether done explicitly using xsl:copy or implicitly using the built-in template rule, is required to copy all the in-scope namespaces of the element being copied.

I've run it under 9.7 and that appears to deliver the same (correct) result.

If you want to drop unused namespaces, try adding a fallback template rule

   <xsl:template match="*">
      <xsl:copy copy-namespaces="no">
         <xsl:apply-templates select="@*, node()"/>
      </xsl:copy>
   </xsl:template>

RE: Extra xmlns attributes being added to children elements - Java Saxon-EE 11.3 - Added by Cory Madden almost 2 years ago

Thank you for the comments. I took my example code and processed it through Saxon 9.7.0.2 and Saxon 11.3. The xsl:mode on-no-match="shallow-copy" works differently in the two versions.

In Saxon 9.7.0.2: (example page https://cory-gallena.oudemo.com/testing.html does contain some of our system code at the bottom of the HTML)

<!DOCTYPE HTML>
<html>
   <body>
      <div class="item-9">		
         <h1>This is output with Saxon 9.7.0.2</h1>	
      </div>
   </body>
</html>

In Saxon 11.3: (example https://program-examples.oudemo.com/xsl-question/test.html does contain some of our system code)

<!DOCTYPE HTML>
<html>
   <body>	
      <div xmlns:ouc="http://omniupdate.com/XSL/Variables" class="item-9">		
         <h1>This should output</h1>
     </div>
</body>
</html>

Full code example (with our system code) XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" 
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:xs="http://www.w3.org/2001/XMLSchema"
				xmlns:ou="http://omniupdate.com/XSL/Variables"
				xmlns:fn="http://omniupdate.com/XSL/Functions"
				xmlns:ouc="http://omniupdate.com/XSL/Variables"
				exclude-result-prefixes="xsl xs ou fn ouc">

	<xsl:output method="html" version="5.0" indent="yes" encoding="UTF-8" />
	
	<xsl:mode on-no-match="shallow-copy" />
	<xsl:template match="processing-instruction('pcf-stylesheet')" mode="#all" />

	<xsl:template match="ouc:*">
		<xsl:apply-templates mode="#current" />
	</xsl:template>

	<xsl:template match="/document">
		<html>
			<body>
				<xsl:apply-templates select="ouc:div[@label='mylabel']" /> 
			</body>
		</html>
	</xsl:template>

</xsl:stylesheet>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<?pcf-stylesheet path="/common.xsl" extension="html" ?>

<document xmlns:ouc="http://omniupdate.com/XSL/Variables">
	<ouc:div label="mylabel" group="Everyone">
		<div class="item-9">
			<h1>This is output with Saxon 11.3</h1>
		</div>
	</ouc:div>
</document>

Can you confirm this the new desired behavior?

RE: Extra xmlns attributes being added to children elements - Java Saxon-EE 11.3 - Added by Cory Madden almost 2 years ago

Thank you for the clarification! I will inform our team of this change, I will repost if they have any additional questions.

    (1-6/6)

    Please register to reply