public void MatchRoot() { XmlDocument xsltDoc = new XmlDocument(); xsltDoc.LoadXml( @" <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method='xml' omit-xml-declaration='no' encoding='UTF-8'/> <xsl:template match='/'><root>Matched</root></xsl:template> </xsl:stylesheet> " ); XslTransform xslt = new XslTransform(); xslt.Load( xsltDoc ); StringBuilder builder = new StringBuilder(); XmlWriter writer = new XmlTextWriter( new StringWriter( builder ) ); CollectionOfSimple c = new CollectionOfSimple( true ); ObjectXPathContext context = new ObjectXPathContext(); context.DetectLoops = true; XPathNavigator nav = context.CreateNavigator( c ); xslt.Transform( nav, null, writer, null ); writer.Close(); Assert.AreEqual( "<root>Matched</root>", builder.ToString() ); }
public void LoadInDocument() { CollectionOfSimple c = new CollectionOfSimple( true ); ObjectXPathContext context = new ObjectXPathContext(); context.NamespaceManager.AddNamespace( "sdf", Namespaces.SDF ); XPathNavigator nav = context.CreateNavigator( c ); for( int i=0; i<100000; i++ ) { nav.MoveToRoot(); XmlDocument original = new XmlDocument(); original.Load( nav.ReadSubtree() ); } }
public void IdentityTransform() { XmlDocument xsltDoc = new XmlDocument(); xsltDoc.LoadXml( @" <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method='xml' omit-xml-declaration='no' encoding='UTF-8'/> <xsl:template match='@*|node()'> <xsl:copy> <xsl:apply-templates select='@*|node()'/> </xsl:copy> </xsl:template> </xsl:stylesheet> " ); XslTransform xslt = new XslTransform(); xslt.Load( xsltDoc ); StringBuilder builder = new StringBuilder(); XmlWriter writer = new XmlTextWriter( new StringWriter( builder )); CollectionOfSimple c = new CollectionOfSimple( true ); ObjectXPathContext context = new ObjectXPathContext(); context.NamespaceManager.AddNamespace( "sdf", "http://www.byte-force.com/schemas/SDF" ); XPathNavigator nav = context.CreateNavigator( c ); XmlDocument original = new XmlDocument(); original.Load( nav.ReadSubtree() ); nav.MoveToRoot(); Console.WriteLine( original.InnerXml ); string originalXml = original.InnerXml; xslt.Transform( nav, null, writer, null ); writer.Close(); Console.Write( builder.ToString() ); Assert.AreEqual( originalXml, builder.ToString() ); }
public void Xslt() { XmlDocument xsltDoc = new XmlDocument(); xsltDoc.LoadXml( @" <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method='xml' omit-xml-declaration='no' encoding='UTF-8'/> <xsl:template match='@*|node()'> <xsl:copy> <xsl:apply-templates select='@*'/> <xsl:apply-templates select='node()'/> </xsl:copy> </xsl:template> </xsl:stylesheet> " ); XslTransform xslt = new XslTransform(); xslt.Load( xsltDoc ); CollectionOfSimple c = new CollectionOfSimple( true ); ObjectXPathContext context = new ObjectXPathContext(); context.NamespaceManager.AddNamespace( "sdf", Namespaces.SDF ); XPathNavigator nav = context.CreateNavigator( c ); for( int i=0; i<100000; i++ ) { StringBuilder builder = new StringBuilder(); XmlWriter writer = new XmlTextWriter( new StringWriter( builder )); XsltArgumentList xslArg = new XsltArgumentList(); nav.MoveToRoot(); xslt.Transform( nav, xslArg, writer, null ); writer.Close(); } }