Skip to content

Commit

Permalink
Fix bug #4344 - xsl:stylesheet always ignored xsl template contents.
Browse files Browse the repository at this point in the history
  • Loading branch information
Atsushi Eno committed Aug 9, 2013
1 parent 2f33410 commit b62bb26
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions mcs/class/System.XML/Mono.Xml.Xsl/XslStylesheet.cs
Expand Up @@ -376,6 +376,8 @@ private void HandleInclude (Compiler c)
return; // Already done.

c.PushInputDocument (included);
included.MoveToRoot ();
included.MoveToFirstChild ();

while (c.Input.NodeType != XPathNodeType.Element)
if (!c.Input.MoveToNext ())
Expand All @@ -387,6 +389,7 @@ private void HandleInclude (Compiler c)
templates.Add (new XslTemplate (c));
}
else {
c.Input.MoveToFirstChild ();
do {
if (c.Input.NodeType != XPathNodeType.Element)
continue;
Expand Down
33 changes: 31 additions & 2 deletions mcs/class/System.XML/Test/System.Xml.Xsl/XslTransformTests.cs
Expand Up @@ -2226,7 +2226,6 @@ public void RejectCurrencySymbolAsNumber ()
Assert.IsTrue (sw.ToString ().IndexOf ("NO") > 0);
}

#if NET_2_0
[Test] // bug #349375
public void PreserveWhitespace ()
{
Expand Down Expand Up @@ -2416,6 +2415,36 @@ public void define_text_constant (string name, string value)
}

private bool valueHasBeenSet;
#endif

[Test] // bug #4434
public void IncludeProcessStylesheet ()
{
string includedXsl = @"<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:doc='http://nwalsh.com/xsl/documentation/1.0' exclude-result-prefixes='doc' version='1.0'>
<doc:template name='foo' />
<xsl:template name='foo'>
<foo />
</xsl:template>
</xsl:stylesheet>";
StreamWriter includedWriter = new StreamWriter ("include.xsl");
includedWriter.WriteLine (includedXsl);
includedWriter.Close ();
XslCompiledTransform transform = new XslCompiledTransform ();
string xsl = @"<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:include href='include.xsl' />
<xsl:template match='/'>
<xsl:call-template name='foo' />
</xsl:template>
</xsl:stylesheet>";
XmlReader xslReader = XmlReader.Create (new StringReader (xsl));
transform.Load (xslReader);
XmlReader inputReader = XmlReader.Create (new StringReader ("<bar />"));
var sw = new StringWriter ();
XmlWriter outputWriter = XmlWriter.Create (sw);
transform.Transform (inputReader, outputWriter);
outputWriter.Close ();
Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?><foo />", sw.ToString (), "#1");
}
}
}

0 comments on commit b62bb26

Please sign in to comment.