Re: [xsl] "mode" not working as expected

Subject: Re: [xsl] "mode" not working as expected
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 08 Jul 2010 20:34:20 -0400
At 2010-07-08 10:34 -0700, Dick Penny wrote:
I get the expected output displayed from variable $step1out with the XSLT
below(with the two ???? obiviously deleted). However, when I replace the two
???? with mode="abc" my template that generates the attribute xx never
executes. Instead, I get six copies of the namespace agg in variable
$step1out.

Not quite ... you are getting six copies of the <xmp> literal result element. Each one has the agg namespace you attached to it.


To my way of thinking, adding a mode simply further guarantees
execution of this template.

But you've cut out one of the other templates by going into the mode. When not in the mode you have one of your template rules that is in play that causes the difference.


What is going on?

Your <xsl:apply-templates/> is pushing the element named "Rows".


Without the mode your match on "*" is copying the Rows element and pushing the children.

The child "Row" is then matched. Thus the variable has one "Rows" and six "Row"
elements. Your debug is showing the child elements of the element named "Rows", thus you see the six Row elements.


When you add the mode, your <xsl:apply-templates/> is still pushing "Rows" but it isn't being caught by your template rule that copies "Rows". It is being caught by the built-in template rule that pushes the child "Row" elements without copying the "Rows" element.

So this time the variable has six "Row" elements but no "Rows" parent. So when you then push the variable to the debug, you are pushing six "Row" elements, and your debug is exposing the children of "Row". There are no children of "Row", so your six <xmp> elements are empty

I cannot imagine what copied the namespace into $step1out.

Your <xmp> is a literal result element, and the agg namespace in your stylesheet document element is attached to <xmp> because you haven't pruned it with exclude-result-prefixes="agg".


What fundamental idea am I missing?

For the six elements, that the built-in template rule doesn't copy the node, it only pushes the children.


For the namespaces, that literal result elements have namespace nodes just like elements in the input.

I hope this helps.

. . . . . . . . . . . Ken

--
XSLT/XQuery training:   after http://XMLPrague.cz 2011-03-28/04-01
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread