Re: [xsl] node-set in .Net 2.0?

Subject: Re: [xsl] node-set in .Net 2.0?
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Mon, 28 Nov 2005 19:25:54 -0700
Bryan,

Not that it matters, but why are you binding 'ns' instead of 'msxsl'?

Anyway, not important. The following C# will compile to a .NET 2.0 console app:

using System;
using System.Xml;
using System.Xml.Xsl;

namespace ConsoleApplication1
{
   class Program
   {
       static void Main(string[] args)
       {
           XslCompiledTransform xslt = new XslCompiledTransform();
           xslt.Load("test.xsl");
           xslt.Transform("test.xml", "test.html");
       }
   }
}

using the following dummy xml saved as test.xml:

<?xml version="1.0" encoding="utf-8" ?>
<foo>
   <bar>test</bar>
</foo>

and the following xsl transformation file saved as test.xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
               xmlns:ns="urn:schemas-microsoft-com:xslt"
               version="1.0">

<xsl:variable name="list">
<item test="foo">bar</item>
<item test="bar">of chocolate</item>
</xsl:variable>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="ns:node-set($list)/item" />
</xsl:template>
<xsl:template match="item">
<xsl:value-of select="@test"/>:<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>


creates the following output saved as test.html:

foo:barbar:of chocolate

I'm building against the final .NET 2.0 release so I'm not sure where your problem might be. A sample of your xml and xsl transformation file might help clear things up, but until I see it I can't no this for sure.



bryan rasmussen wrote:

Hey

I'm running a node-set heavy transform in .Net, I keep getting the
following error:

The 'Function 'ns:node-set()' has failed.'
If I change the variable that is creating the node-set not to I get
the following error:
The expression passed to this method should result in a NodeSet.

the ns namespace is associated with
xmlns:ns="urn:schemas-microsoft-com:xslt"

IIRC this namespace was allowed in earlier versions of .NET. Does
anyone know if this has changed, has .Net's already arcane nodeset
handling rules changed? Does one have to explicitly allow nodesets to
be created in ones code?

Cheers,
Bryan Rasmussen

Current Thread