469,362 Members | 2,375 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

Programatically Read XSL Params

5
is xpath the best way to programicly read the params an xsl page requires or is there a better way?

Thanks
Dec 3 '08 #1
8 4039
Dormilich
8,652 Expert Mod 8TB
I think there's a misunderstanding. XPath is the/one language to access elements in an xml document tree. and <xsl:param> is a part of the XSLT language. you can't read <xsl:param> by XPath, though you can use them inside XPath. (well, technicly it should be possible but XSLT provides easier access - you read them in XSLT by calling the parameter name with a prefixed $ sign: $param_name (like variables in PHP))
Dec 3 '08 #2
aday
5
thanks

but I am not sure I understand.......

I am writing a winforms program in C# (3.5 framework) and I need to read the params from am xsl doc and present them to the user to fill in the required values.
Dec 3 '08 #3
Dormilich
8,652 Expert Mod 8TB
as far as I understand XSLT, params (in the form of <xsl:param> are for the internal use in the stylesheet. usually a xsl stylesheet is used to transform one xml into another xml (or html, or text). so what the xsl contains is out of interest as long as it does its job.

out of interest, what is your xsl doc supposed to do, maybe we're talking about different things.

regards
Dec 3 '08 #4
aday
5
basicly I am building a Code and SQL Stored Procedure generation tool (vs addin) for vs.net all my templates are xsl docs that users can create and add. And my xml data is generated using the SqlXmlCommand in vs.net

Say a user has created a template (xsl doc) that accepts a param called "postfix" and "prefix" that will be used in the transformation.

I would like to be able to read the params that are defined in the xsl doc so I can then request the value from the user using the tool for the values.

I hope this explanes it .
Dec 3 '08 #5
Dormilich
8,652 Expert Mod 8TB
you make me curious. your users can write xsl from scratch? maybe you should post some code, because I still think we're talking about different things.

you can get the parameter names via DOM, since xsl is xml. XPath is possible too, if you load the xsl into an xml reader (don't know what C# provides). It really depends on how the xsl is created... there might be more and easier ways.

regards
Dec 3 '08 #6
jkmyoung
2,057 Expert 2GB
This reminds me of the old javascript way of running xsl.
In order to set parameters, you would actually have to change the values of the parameters of the elements in DOM of the xsl, then run the transformation.

Anyways, I think you can use SelectNodes("//xsl:template[@match]/xsl:param/@name", nsmgr)
where nsmgr is your namespace manager, and has the namespace xsl defined.

Assumptions:
You have a main template which uses match.
When you call your other matched templates, you don't use parameters; (Usually the case.)
Dec 3 '08 #7
aday
5
I have added a sample xsl doc.

Here is an example of me setting the param in c#

Expand|Select|Wrap|Line Numbers
  1.  
  2.                //Initialize
  3.                 string returnValue = string.Empty;
  4.                 XslCompiledTransform xslDoc = new XslCompiledTransform();           
  5.                 XmlUrlResolver xslResolver = new XmlUrlResolver();
  6.                 XsltArgumentList xslArg = new XsltArgumentList();
  7.  
  8.                 //Load XSL Template
  9.                 xslDoc.Load(FullTemplateName);
  10.  
  11.                 //Get Table Columns In XML
  12.                 XmlReader xmlColumnList = GetDatabaseTableColumnList(ddlDatabases.Text, TableName);
  13.  
  14.                 //xmlColumnList.MoveToContent();
  15.                 TextWriter swTrasformationOutput = new StringWriter();
  16.  
  17.                 //Set Required Arguments
  18.                 xslArg.AddParam("spPrefix", "", txtPrefix.Text);
  19.  
  20.                 //Do Transformation
  21.                 xslDoc.Transform(xmlColumnList, xslArg, swTrasformationOutput);
  22.                 swTrasformationOutput.Flush();
  23.  
  24.                 return swTrasformationOutput.ToString();
  25.  
  26.  
Attached Files
File Type: txt Ivey_Add.txt (1.9 KB, 553 views)
Dec 4 '08 #8
aday
5
Thanks, I will try this.... I assume you are doing this with XPath

@jkmyoung
Dec 4 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Logan McKinley | last post: by
3 posts views Thread by Stan Huff | last post: by
4 posts views Thread by brent | last post: by
4 posts views Thread by Kevin Vogler | last post: by
1 post views Thread by Robert Burdick [eMVP] | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.