从XSLT文件中获取变量值 [英] Getting Variable values out of and XSLT file

查看:67
本文介绍了从XSLT文件中获取变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定是否存在从XSL文件中获取参数或变量值的方法.例如,如果我有以下内容:

I wanted to find out if there is a way of getting a parameter or variable value out of an XSL file. For example, if I have the following:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:variable name="username" select ="usertest"/>
  <xsl:variable name="password" select ="pass"/>
  <!-- ... -->
</xsl:stylesheet>

我想从XSL中读取 username password 值,并将它们用于身份验证.我正在使用ASP.Net和C#对XML文件执行实际的转换.

I would like to read the username and password values from the XSL and use them for authentication. I am using ASP.Net and C# to perform the actual transform on an XML file.

有人可以和我共享代码,让我从ASP.NET/C#中读取XSL变量.预先感谢您的帮助.

Could someone please share code with me that would allow me to read the XSL variables from ASP.NET/C#. Thanks in advance for the help.

推荐答案

感谢Everone.这是最终有效的方法:

Thanks Everone. Here is what finally worked:

用于测试目的的客户端(带有vbscript的ASP):

Client (asp with vbscript) Used for Testing Purposes:

<%

//Create Object
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
//Set up the object with the URL
'xmlhttp.open "POST" ,"http://localhost/ASP_Test/receiveXML.asp",False

//Create DOM Object
Set xmldom = CreateObject("Microsoft.XMLDOM")
xmldom.async = false

//Load xls to send over for transform
xmldom.load(Server.MapPath("/ASP_Test/masterdata/test.xsl"))

//Send transform file as DOM object
xmlhttp.send xmldom
%>
//////////////////////////////////////////////////////////////////////////
On the Server Side: (aspx with C#) Accepts xslt and process the transform:

//file path for data xml
String xmlFile = ("\\masterdata\\test.xml");
//file path for transformed xml
String xmlFile2 = ("\\masterdata\\out.xml");


XmlTextReader reader = new XmlTextReader(Request.InputStream);
Transform(xmlFile, reader, xmlFile2);

 public static string Transform(string sXmlPath, XmlTextReader xslFileReader, string outFile)
        {
            try
            {
                //load the Xml doc
                XPathDocument myXPathDoc = new XPathDocument(sXmlPath);
                XslCompiledTransform myXslTrans = new XslCompiledTransform();

                //load the Xsl
                myXslTrans.Load(xslFileReader);

                //create the output stream
                XmlTextWriter myWriter = new XmlTextWriter
                    (outFile, null);

                //do the actual transform of Xml
                myXslTrans.Transform(myXPathDoc, null, myWriter);

                myWriter.Close();
                return "Done";
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }

这篇关于从XSLT文件中获取变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆