Project

Profile

Help

Saxon .NET Parameters

Added by Anonymous almost 16 years ago

Legacy ID: #5278380 Legacy Poster: Masty (masty)

Hello, I'm trying to add a parameter to my XSLTransformer in Saxon.Net. Using the native .Net libs I would do something like this: XsltArgumentList argList = new XsltArgumentList(); argList.AddParam(key, String.Empty, val); transform.Transform(reader, argList, result); In saxon I am trying to use the SetParameter method but I get an exception with a cryptic "CCE" message. Here's my saxon code: transform.SetParameter(new QName(String.Empty, String.Empty, key), XdmAtomicValue.WrapExternalObject(val)); transform.Run(result); I suspect I'm doing something wrong with the params I'm using for SetParameter, but there are no alternatives in the .Net API that are jumping out at me. Can someone please point me in the right direction? Thanks Masty


Replies (4)

Please register to reply

RE: Saxon .NET Parameters - Added by Anonymous almost 16 years ago

Legacy ID: #5279631 Legacy Poster: Michael Kay (mhkay)

It's always worth quoting an error message in full even if it seems cryptic - it might make sense to someone else who knows the software better, or who has seen it before. It's also worth providing a little bit more of your code (what is "val", for example?), - preferably enough so that someone else can try running it - and indicating more precisely where the error comes from.

RE: Saxon .NET Parameters - Added by Anonymous almost 16 years ago

Legacy ID: #5282645 Legacy Poster: Masty (masty)

key and val are both strings - key is the parameter name and val is the parameter value. The full error message [Saxon.Api.DynamicError]: {"CCE"} Data: {System.Collections.ListDictionaryInternal} HelpLink: null InnerException: null Message: "CCE" Source: "saxon9api" StackTrace: " at Saxon.Api.XsltTransformer.Run(XmlDestination destination)\r\n at <<my stack>> TargetSite: {Void Run(Saxon.Api.XmlDestination)} What I really need is an example of working code passing parameters into a transform in Saxon .Net, but I can't find one anywhere. Is XdmAtomicValue the right thing to be using? It seemed to be the most appropriate XdmValue for me to use.

RE: Saxon .NET Parameters - Added by Anonymous almost 16 years ago

Legacy ID: #5282743 Legacy Poster: Michael Kay (mhkay)

There's an example in the XsltExamples.cs program that's part of the saxon-resources distribution: /** * This shows how to set a parameter for use by the stylesheet. Use * two transformers to show that different parameters may be set * on different transformers. */ public static void ExampleParam(String sourceUri, String xsltUri) { // Create a Processor instance. Processor processor = new Processor(); // Load the source document XdmNode input = processor.NewDocumentBuilder().Build(new Uri(sourceUri)); // Compile the stylesheet XsltExecutable exec = processor.NewXsltCompiler().Compile(new Uri(xsltUri)); // Create two transformers with different parameters XsltTransformer transformer1 = exec.Load(); XsltTransformer transformer2 = exec.Load(); transformer1.SetParameter(new QName("", "", "a-param"), new XdmAtomicValue("hello to you!")); transformer2.SetParameter(new QName("", "", "a-param"), new XdmAtomicValue("goodbye to you!")); // Now run them both transformer1.InitialContextNode = input; XdmDestination results1 = new XdmDestination(); transformer1.Run(results1); transformer2.InitialContextNode = input; XdmDestination results2 = new XdmDestination(); transformer2.Run(results2); Console.WriteLine("1: " + results1.XdmNode.StringValue); Console.WriteLine("2: " + results2.XdmNode.StringValue); } This uses "new XdmAtomicValue(string)". Using WrapExternalObject is wrong - that's where you want to pass an object that will be wrapped for passing to extension functions, rather than being converted to a regular XDM value. I don't know why it failed the way it did, though.

RE: Saxon .NET Parameters - Added by Anonymous almost 16 years ago

Legacy ID: #5282780 Legacy Poster: Masty (masty)

Thanks, no idea how I missed the constructor :/

    (1-4/4)

    Please register to reply