How to retrieve global parameters with .NET ?
Added by Anonymous over 14 years ago
Legacy ID: #8337485 Legacy Poster: tg (pilger81)
Hi, how can I retrieve global parameters set in a stylesheet? for example: <xsl:param name="parameter_name"></xsl:param> I created a windows form where I can set Parameters. these values are later overgiven with SetParameter (~"parameter_name", "test"). that works fine. But Id like to parse the stylesheet before and autofill the form with the parameters set in the stylesheet. Just to make it easier and more comfortable for the user. I hope its clear what I mean. sry for my bad english. I found some solutions on that for java. but not for c#. maybe someone has an idea? greetings
Replies (9)
Please register to reply
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8337497 Legacy Poster: tg (pilger81)
sry this should be in "help" not in open discussion ... to make my post clearer. I mean something like this: XsltTransformer atransformer; string[] params = atransformer.GetParameters(); greetings
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8337534 Legacy Poster: Michael Kay (mhkay)
The XsltExecutable in Saxon.Api unfortunately doesn't give you any access to this information. However you can call Load() to get an XsltTransformer, and on this you can get the Java net.sf.saxon.Controller as the value of the Implementation property. Although this is a Java-derived object, you can manipulate it as any .NET object, though the style may be a little unfamiliar, e.g. method names beginning lower-case. You will have to add a reference to the saxon9he.dll (or -pe or -ee) to your application. From the Controller you can do getExecutable().getCompiledGlobalVariables() which is a (Java) HashMap from names to variable definitions; for a global parameter (as distinct from a Variable) the value will be of class net.sf.saxon.instruct.GlobalParam. Sorry that's a bit circuitous, it's the best I can come up with at the moment.
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8337896 Legacy Poster: tg (pilger81)
thanks mr kay =) that works fine
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8348311 Legacy Poster: tg (pilger81)
its me again. well, as I said it seems to work fine. but now I have a problem. :-/ when I have a param like this: <xsl:param name="examplXML"> <xsl:value-of select="document($path,.)/config/examplXML"/> </xsl:param> I get this: DocumentInstr(ValueOf(SimpleContentConstructor(((document($path, .)/child::element(config, xs:anyType))/child::element(examplXML, xs:anyType)), " "))) which is not good. it works great with params written in normal text but when I write a param with xslt expressions he tries to interpret it I guess. do you have an idea how to solve this?
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8348573 Legacy Poster: Michael Kay (mhkay)
Don't simply do toString() on the value of the select expression. The user interface is up to you, but I would say: if the select expression is a an instance of Literal, display its string value; otherwise display something like "(computed value)". The original text of the expression from the source stylesheet is not available in the compiled code.
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8348586 Legacy Poster: Michael Kay (mhkay)
Incidentally, the compiled code would be much less convoluted if you wrote the xsl:param like this: <xsl:param name="examplXML" select="document($path,.)/config/examplXML"/> Using xsl:value-of in this kind of situation is really bad coding, but unfortunately very common: it forces saxon to read the document and then make a copy of it.
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8351126 Legacy Poster: tg (pilger81)
I decided to retreive the params on another way. I parse the source xslt file and write the given values into a string, and put them in a list. and so on. basically like this: XmlReader xmlReader = null; xmlReader = XmlReader.Create(xsltfile); while (xmlReader.Read()) { string param, value = ""; if (xmlReader.Name == "xsl:param" && xmlReader.IsStartElement() && xmlReader.Depth == 1) { bool select = false; param = xmlReader.GetAttribute("name"); if (xmlReader.MoveToAttribute("select")) { value = xmlReader.ReadInnerXml(); select = true; } if (xmlReader.MoveToContent() != XmlNodeType.None && select == false) { value = xmlReader.ReadInnerXml(); value = Item.value.Trim(); select = false; } Program.konfiguration.parameters.Add(Item); } } xmlReader.Close(); works fine. and it seems to run fast.
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8351146 Legacy Poster: Michael Kay (mhkay)
Fine. Be aware that you aren't accessing included/imported stylesheets, and you're relying on the namespace prefix being "xsl". But as a cheap-and-cheerful solution, it's fine.
RE: How to retrieve global parameters with .NET ? - Added by Anonymous over 14 years ago
Legacy ID: #8351157 Legacy Poster: tg (pilger81)
I will consider these things. thx :) and really thank you for your time!
Please register to reply