473,373 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 4385
Dormilich
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
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,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.

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

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, 597 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

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

Similar topics

5
by: Logan McKinley | last post by:
I was wondering if there is any way for me to read the device manager in my C# program? I have a program that crashes when some third party hardware is not installed or is set to the wrong port...
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
3
by: Stan Huff | last post by:
Is there any way to disable the "params" on a particular invocation so that one can pass an array containing the arguments and not have receiver get an array having you argument array stuffed into...
4
by: brent | last post by:
Currently our application is reading from the web.config, and retrieves a section, "softwareRequirements". Because the section will begin to grow dramatically, I'd like to place it in the SQL...
4
by: Kevin Vogler | last post by:
I need to read the value of a hidden field on a remote HTML page and then use that value in a form submit on my local page. How can I read the hidden field programatically? Thanks in advance....
0
by: mike | last post by:
Hi, When I programatically Bind a DataSource to DetailsView it does not fire "ModeChanged" event. This is first time i am trying to use ASP.NET DetailsView control. I have played with some of the...
1
by: Robert Burdick [eMVP] | last post by:
Hello All: I cannot seem to get a simple programmatic post to work. From one ASPX page, I want to generate HTML from another page. Thus, I programatically post to the second page and read the...
5
by: Ranginald | last post by:
Hi, I have a question about encrypting connection strings in an asp.net 2.0 app in a shared hosting environment. From what I have read, I believe I need to programatically encrypt and decrypt...
7
by: The Mad Ape | last post by:
Hi I have code to programatically create a label. It works but when I try to call a sub to create a tooltip it does not work. I do not get an error so have no idea what it wrong. Please review...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.