[System.XML] Add unit test for #18118
[mono.git] / mcs / class / System.XML / Test / System.Xml.Xsl / XslCompiledTransformTests.cs
1 using NUnit.Framework;
2 using System.IO;
3 using System.Xml;
4 using System.Xml.XPath;
5 using System.Xml.Xsl;
6
7 namespace MonoTests.System.Xml.Xsl
8 {
9         [TestFixture]
10         public class XslCompiledTransformTests
11         {
12                 [Test]
13                 public void GlobalVariableReferencesAnotherGlobalVariable ()
14                 {
15                         string xsl = @"<xsl:stylesheet version='1.0'
16 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
17 <xsl:variable name='global2'><xsl:value-of select='root/@attr' /></xsl:variable>
18 <xsl:variable name='global1'>
19         <xsl:for-each select='//foo'>
20                 <xsl:if test='@attr = $global2'>
21                         <xsl:value-of select='name(.)' />: <xsl:value-of select='@attr' />
22                 </xsl:if>
23         </xsl:for-each>
24 </xsl:variable>
25 <xsl:template match='/'>
26         <root>
27                 <xsl:value-of select='$global1' />
28         </root>
29 </xsl:template>
30 </xsl:stylesheet>";
31                         StringWriter sw = new StringWriter ();
32                         XslCompiledTransform t = new XslCompiledTransform ();
33                         t.Load (new XPathDocument (new StringReader (xsl)));
34                         t.Transform (new XPathDocument (new XmlTextReader (new StringReader ("<root attr='B'><foo attr='A'/><foo attr='B'/><foo attr='C'/></root>"))), null, sw);
35                         Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?><root>foo: B</root>", sw.ToString ());
36                 }
37         }
38 }