locked
XML RRS feed

  • Question

  • Hi Can you please advise me an example that demonstrates an XML document containing an XSL style sheet with-in the document? My project requirements do not allow referencing Xsl as an external file. 

     Ideally I will need to have Xsl, Xml and CSS with-in an Xml document and stream to a literal or label (using ASP.NET 2.0) for formatting and display. Please advice. Thanks in advance.

    Sunday, February 18, 2007 3:52 AM

Answers

  • You can imbed XSLT into XML by adding xsl:transform element as a node in your XML.

    To load this XSLT to XslCompiledTransform you would need to create XmlReader over the node with xsl:transform and pass this reader to XslCompiledTransform.Load().

    To create xml reader that starts with xsl:transform:

    1. if you have entire XML loaded (most likely) you can use method XPathNavigator.ReadSubtree(). (You'd need create XPathNavigator over your cache first -- XmlNode.CreateNavigator() or XPathDocument.CreateNavigator().)

    2. If you don't you can XmlReader.Create(_entire_XML_file) and then use Read() method up to the moment it reaches xsl:transform element, then pass this reader to XslCompiledTransform.Load(). It would read its part of XML and stop on end tag of xsl:transform or right after it so you would be able to continue reading the XML with this reader.

    Last method is more advanced and less tested. (There is known bug in it – all namespace used in the imbedded xsl should be defined inside xsl:transform element.)

     

    Sunday, February 18, 2007 3:53 AM