Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XSL from a string

0 views
Skip to first unread message

L. Smith

unread,
Feb 20, 2003, 1:41:01 PM2/20/03
to
I have xsl content that is coming from a database. So I need to be able to
convert it from a string to xsl so I can use it for a transform. Does
anyone know how to do this in c# or vb.net?

Thanks in advance,

Linda


Joel Askey

unread,
Feb 20, 2003, 8:05:45 PM2/20/03
to
The XslTransform object ( System.Xml.Xsl ) has a Load function which has an
overload which takes a string argument.

"L. Smith" <lsm...@utilityguide.com> wrote in message
news:uLXUf#Q2CHA...@TK2MSFTNGP11.phx.gbl...

L. Smith

unread,
Feb 21, 2003, 9:29:28 AM2/21/03
to
Yes, however, I believe that the string argument is there to reference a
URL. I do not have a URL, all I have is the xsl data contained in a string.

"Joel Askey" <joel....@shs.com> wrote in message
news:esL5dVU2...@TK2MSFTNGP11.phx.gbl...

Shawn Farkas [MS]

unread,
Feb 21, 2003, 5:47:01 PM2/21/03
to
Hi Linda,

You can load an XslTransform with an XPathNaviagator. And you can get
an XPathNaviagtor from an XmlDocument object. If you create a new
XmlDocument object, it has a LoadXml() method that will load raw XML from a
string for you. You can then call CreateNavigator on the XmlDocument to get
the navigator to pass to the XslTransform::Load method.

-Shawn

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias, this alias is for newsgroup
purposes only.


"Joel Askey" <joel....@shs.com> wrote in message
news:esL5dVU2...@TK2MSFTNGP11.phx.gbl...

Kirk Allen Evans

unread,
Feb 25, 2003, 12:28:26 PM2/25/03
to
private void Page_Load(object sender, System.EventArgs e)
{
System.Xml.Xsl.XslTransform trans = new System.Xml.Xsl.XslTransform();
System.IO.StringReader reader = new System.IO.StringReader(getXSLT());
System.Xml.XPath.XPathDocument doc = new
System.Xml.XPath.XPathDocument(reader);
trans.Load(doc);

System.Xml.XmlTextReader xmlreader = new
System.Xml.XmlTextReader(Server.MapPath("xmlfile1.xml"));
System.Xml.XPath.XPathDocument xmlSource = new
System.Xml.XPath.XPathDocument(xmlreader);
trans.Transform(xmlSource,null,Response.OutputStream);
reader.Close();
xmlreader.Close();
}

private string getXSLT()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<?xml version='1.0'?><xsl:stylesheet version='1.0' ");
sb.Append("xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>");
sb.Append("<xsl:template match='*'>");
sb.Append("<xsl:copy><xsl:apply-templates select='*'/>");
sb.Append("</xsl:copy></xsl:template></xsl:stylesheet>");
return(sb.ToString());
}

--
Kirk Allen Evans
Author, "XML And ASP.NET", New Riders Publishing
www.xmlandasp.net
http://dotnetweblogs.com/kaevans

"L. Smith" <lsm...@utilityguide.com> wrote in message
news:uLXUf#Q2CHA...@TK2MSFTNGP11.phx.gbl...

0 new messages