Exemplo n.º 1
0
        public void TestTransformCompileFile()
        {
            var xslt     = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0"">
<xsl:emplate match='foo'><a>bar=<xsl:value-of select='bar'/>;<xsl:apply-templates select='baz'/></a></xsl:emplate>
<xsl:template match='baz'>baz=<xsl:value-of select='.'/>;</xsl:template>
</xsl:stylesheet>";
            var expected = "'xsl:emplate' cannot be a child of the 'xsl:stylesheet' element.";

            (var transform, var error) = XmlEditorService.CompileStylesheet(xslt, "test.xml");
            Assert.NotNull(error);
            Assert.IsNull(transform);

            Assert.AreEqual(expected, error.ErrorText);
        }
Exemplo n.º 2
0
        public void TestTransform()
        {
            var xml =
                @"<?xml-stylesheet type='text/xsl' href='hello.xsl'?>
<foo><bar>thing</bar><baz>other</baz></foo>";
            var xslt     = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0"">
<xsl:template match='foo'><a>bar=<xsl:value-of select='bar'/>;<xsl:apply-templates select='baz'/></a></xsl:template>
<xsl:template match='baz'>baz=<xsl:value-of select='.'/>;</xsl:template>
</xsl:stylesheet>";
            var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><a>bar=thing;baz=other;</a>";

            (var transform, var error) = XmlEditorService.CompileStylesheet(xslt, "test.xml");
            Assert.NotNull(transform);
            Assert.IsNull(error);

            var outWriter = new EncodedStringWriter(System.Text.Encoding.UTF8);

            using (var reader = XmlReader.Create(new StringReader(xml))) {
                transform.Transform(reader, null, outWriter);
            }
            Assert.AreEqual(expected, outWriter.ToString());
        }