how can I retrieve global parameters set in a stylesheet?
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
sry this should be in "help" not in open discussion ...
to make my post clearer. I mean something like this:
string params = atransformer.GetParameters();
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.
thanks mr kay =)
that works fine
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:
I get this:
.)/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?
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.
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.
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);
string param, value = "";
if (xmlReader.Name == "xsl:param" && xmlReader.IsStartElement() &&
xmlReader.Depth == 1)
bool select = false;
param = xmlReader.GetAttribute("name");
value = xmlReader.ReadInnerXml();
select = true;
if (xmlReader.MoveToContent() != XmlNodeType.None && select == false)
value = xmlReader.ReadInnerXml();
value = Item.value.Trim();
select = false;
works fine. and it seems to run fast.
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.
I will consider these things. thx :)
and really thank you for your time!
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.