471,886 Members | 1,163 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,886 software developers and data experts.

Programatically Read XSL Params

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

Dec 3 '08 #1
8 4101
8,658 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

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
8,658 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.

Dec 3 '08 #4
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
8,658 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.

Dec 3 '08 #6
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.

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
I have added a sample xsl doc.

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

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

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
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.