Re: [xsl] a weird bug today, tree seems to change mid transform

Subject: Re: [xsl] a weird bug today, tree seems to change mid transform
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Sat, 08 Sep 2007 16:33:34 +0200
Abel Braaksma wrote:
bryan rasmussen wrote:
I don't have access to the code that is doing it, but it
seems evident that somehow it is tampering with the DOM during the
transform.


Just thinking out loud here, but what happens if you do a copy-preprocessing and then re-apply the templates to the msxml:nodeset of the result? That way you force your XSLT to operate on a copy of the input object and there can be no tampering in-between anymore:


<xsl:template match="/">
   <xsl:variable name="copy">
      <xsl:apply-templates mode="copy" />
   </xsl:variable>
   <xsl:apply-templates select="msxml:nodeset($copy)" />
</xsl:template>

<xsl:template match="node() | @*" mode="copy">
   <xsl:copy>
      <xsl:apply-templates select="node() | @*" mode="copy" />
   </xsl:copy>
</xsl:template>

<xsl:template match="*" mode="copy">
<xsl:copy>
<xsl:attribute name="original-id"><xsl:value-of select="generate-id()" /></xsl:attrribute>
<xsl:apply-templates select="node() | @*" mode="copy" />
</xsl:copy>
</xsl:template>


<xsl:template match="node() | @*" >
   <xsl:copy>
      <xsl:apply-templates select="node() | @*" mode="copy" />
   </xsl:copy>
</xsl:template>

<xsl:template match="*" >
<xsl:copy>
<xsl:attribute name="new-id"><xsl:value-of select="generate-id()" /></xsl:attrribute>
<xsl:apply-templates select="node() | @*" mode="copy" />
</xsl:copy>
</xsl:template>



<xsl:template match="x">
<xsl:copy>
<xsl:attribute name="new-id"><xsl:value-of select="generate-id()" /></xsl:attrribute>
<xsl:variable .... do your thing with @x />
... do some more with x here ...


      <xsl:apply-templates select="node() | @*" mode="copy" />
   </xsl:copy>
</xsl:template>



Now your output should also contain, on each node, the attributes "original-id" and "new-id". These should be *different* for each and every node!!! You may take this step even a bit further to see if attributes are treated differently:

<xsl:template match="*">
   <xsl:for-each select="@*">
      <xsl:copy />
      <xsl:attribute name="{concat('id-of-attr-', name())}" />
   </xsl:for-each>
</xsl:template>

do the same for the copy mode. It will get quite messy, but you will get some insight in what is going on under the hood.... (meaning: you will get insight when generated ids are equal and you know it is an MS bug, you won't get insight if all ids are different as they should be).

Hopefully, the copy trick, which is an easy workaround, can be applied to all your stylesheets, if it indeed works. It is bad, but not that bad as a hack per issue (like your following-sibling trick).

Cheers,
-- Abel Braaksma

Current Thread