This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: suprised by <xsl:copy-of select="@*"/>


> I was suprised that this template:
>
> <xsl:template match="cell">
>     <td>
>         <xsl:copy-of select="@*"/>
>         <xsl:apply-templates/>
>     </td>
> </xsl:template>
>
> against this XML:
>
> <cell colspan="2" bgcolor="#CC0000">
>    some other stuff...
> </cell>
>
> produced this output:
>
> <td colspan="2" bgcolor="#CC0000">
>     result of transform on other stuff...
> </td>
>
> Why did I get
> <td colspan="2" bgcolor="#CC0000">
> instead of
> <td>colspan="2" bgcolor="#CC0000"

Basically, because <xsl:copy-of seelct="@*"/> creates attribute nodes onthe
result tree, and your the output [<td>colspan="2" bgcolor="#CC0000"] could
never be produced by serializing attribute nodes.

<td>.....</td>, after parsing, becomes an element node on the stylesheet
tree. This element node acts as a special kind of instruction, called a
literal result element. When a literal result element is "instantiated"
(i.e. executed) it creates an element node on the result tree, and then
instantiates the instructions that are children of the literal result
element in the stylesheet tree. The first such instruction is <xsl:copy-of>,
and this creates attribute nodes which are added to the "current" element
node on the result tree.

I spelt this out laboriously, because I suspect you aren't really thinking
of the process in terms of nodes on trees, but this is essential to
understanding the behavior.

Mike Kay
Software AG


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]