Bug with the .NET XslTransform xslt transformation?

Hi,

I have an C#/ASP.NET application.  Most pages are generated this way:
I extract data from the database, produce an xml string, use a xslt stylesheet to display the page.

I can either send the page as xml with a link to the stylesheet, in which case, the transformation is done by IE or I can transform it on the server with the Transform() method of XslTransform object and send HTML.

Now, usually, this works fine in both cases but I have now a situation where the result is "wildly" different.  I have tested the tranformation using javascript (with the transform method of the ActiveXObject("Msxml2.FreeThreadedDOMDocument")) and it gives me the same result as IE, which makes me feel like the .NET transformation is wrong.

Here is a very small sample of the xslt stylesheet:

<xsl:variable name="local-nodes" select="$xml-doc-root/t:tree/t:node/t:node"/>
<xsl:for-each select="$columns">
   <xsl:for-each select="$xml-doc-root/t:tree/t:node/t:node">
      <xsl:variable name="node" select="."/>
      <xsl:variable name="colspan">
         ...
      </xsl:variable>
      <th colspan="{$colspan}">
         <xsl:value-of select="substring-after($node/@value,'|')"/>
         ...
      </th>
   </xsl:for-each>
</xsl:for-each>

If I replace the select of the second "for-each" with "$local-nodes", I obtain different results when transforming with .NET (I get the same thing with IE, which I expect).

(This is just to illustrate my point with a small code sample that the .NET Transform doesn't process properly)

So anyway, anyone else has experienced something similar.  Any suggestions   Is the .NET Transform() known to be broken

Thanks in advance for any help you may provide.



Answer this question

Bug with the .NET XslTransform xslt transformation?

  • jwellsntr

    By the way I'm experimenting a bit and I have found that by building result fragment tree, and using node-set() instead of selecting my node sets with an xpath expression, I seam to be solving some problems.

    It is as if, when you start using them (fragment trees + node-set()), you have to use them everywhere...
    I find this a little bit distribubing.

    It is always inerpreted correctly in IE though...


  • Rajiv Kumar

    This is an issue with XSLT standards compliance and the handling of result tree fragments.  Your variable $local-nodes is probably a result tree fragment, which according to the XSLT spec cannot be automatically queried using xpath.  To overcome this limitation in the XSLT spec we have provided a helper function to turn a result tree fragment into a node set as follows.  First define the following extension namespace:

    xmlns:msxsl="urn:schemas-microsoft-com:xslt"

    Then wrap your variables in the following function call:

    msxsl:node-set($local-nodes)

    Then you will get the same result as MSXML.


  • Alessandro Contenti

    Thank you very much for your help.

    In my example, local-nodes corresponds to $xml-doc-root/t:tree/t:node/t:node, this is a node set but does it qualify as a result tree fragment
    I already am using the node-set function elsewhere in my code where I "build" my variable from several nodes (with copy-of, for instance).

    However, if I try to use it at this specific location, a get an error (in french):

    Impossible de convertir l'operande en 'fragment de l'arborescence resultat'. Echec de la fonction 'exsl:node-set()'.

    Which would roughly translate to something like:

    Impossible to convert the operand to result tree fragment.  The node-set() function has failed.

    Note that I do not get this message when the code is interpreted by IE.

    Got any further pointers for me

    Thanks again.

  • Bug with the .NET XslTransform xslt transformation?