Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 30, 2011
@mtutty mtutty Fixes #17 4be6c2e
Commits on Jan 02, 2012
@mtutty mtutty Reverted common assembly info.
Changed tabs to four-space indents
Added xml/xslt snippets to unit testing for StyleTask.
d1b2bf0
Commits on Jan 07, 2012
@mtutty mtutty Updated StyleTask to always use new XsltCompiledTransform class. a053d77
Commits on Jan 21, 2012
@rmboggs rmboggs Minor fix to the xsl test files for the StyleTask. Needed for upcomin…
…g changes in StyleTask to start using XslCompiledTransform.
837bf72
@rmboggs rmboggs Merge pull request #18 from mtutty/master
Updates the StyleTask to use the XslCompiledTransform class.
675a514
View
2  examples/StyleTask/SimpleExtensionObject/circle.xsl
@@ -1,5 +1,5 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:myObj="urn:Calculate">
+ xmlns:Calculate="urn:Calculate">
<xsl:template match="data">
<circles>
View
2  examples/StyleTask/SimpleExtensionObject/circles.xml
@@ -1,4 +1,4 @@
-<circles xmlns:myObj='urn:myObj'>
+<circles xmlns:Calculate='urn:Calculate'>
<circle>
<radius>12</radius>
<circumference>75.398223686155</circumference>
View
20 src/NAnt.Core/Tasks/StyleTask.cs
@@ -106,7 +106,7 @@ public class StyleTask : Task {
private string _extension = "html";
private Uri _xsltFile;
private FileInfo _srcFile;
- private FileInfo _outputFile;
+ private FileInfo _outputFile;
private FileSet _inFiles = new FileSet();
private XsltParameterCollection _xsltParameters = new XsltParameterCollection();
private XsltExtensionObjectCollection _xsltExtensions = new XsltExtensionObjectCollection();
@@ -343,9 +343,6 @@ public class StyleTask : Task {
}
}
- // initialize XSLT transform
- XslTransform xslt = new XslTransform();
-
try {
if (XsltFile.IsFile) {
// change current directory to directory containing
@@ -358,15 +355,24 @@ public class StyleTask : Task {
// load the stylesheet
Log(Level.Verbose, "Loading stylesheet '{0}'.", XsltFile);
xslReader = CreateXmlReader(XsltFile);
- xslt.Load(xslReader);
// create writer for the destination xml
writer = CreateWriter(destInfo.FullName);
// do the actual transformation
Log(Level.Info, "Processing '{0}' to '{1}'.",
- srcInfo.FullName, destInfo.FullName);
- xslt.Transform(xml, xsltArgs, writer);
+ srcInfo.FullName, destInfo.FullName);
+
+ XslCompiledTransform xslt = new XslCompiledTransform();
+ string xslEngineName = xslt.GetType().Name;
+
+ Log(Level.Verbose, "Using {0} to load '{1}'.",
+ xslEngineName, XsltFile);
+ xslt.Load(xslReader, new XsltSettings { EnableDocumentFunction = true, EnableScript = true }, new XmlUrlResolver() );
+
+ Log(Level.Verbose, "Using {0} to process '{1}' to '{2}'.",
+ xslEngineName, srcInfo.FullName, destInfo.FullName);
+ xslt.Transform(xml, xsltArgs, writer);
} finally {
// restore original current directory
Directory.SetCurrentDirectory(originalCurrentDirectory);
View
82 tests/NAnt.Core/Tasks/StyleTaskTest.cs
@@ -39,16 +39,20 @@ public class StyleTaskTest : BuildTestBase {
</project>";
private string _xmlSrcFileName = "source";
- private string _xmlSrcFile2Name = "source2";
- private string _xslSrcFileName = "transform";
+ private string _xmlSrcFile2Name = "source2";
+ private string _xmlSingletonFileName = "singleton";
+ private string _xslSrcFileName = "transform";
+ private string _xslPassthroughSrcFileName = "passthrough";
private string _xmlSrcFileExtension = "xml";
private string _xslSrcFileExtension = "xsl";
private string _outputFileExtension = "html";
private string _xmlSrcFileNameFull;
- private string _xmlSrcFile2NameFull;
- private string _xslSrcFileNameFull;
+ private string _xmlSrcFile2NameFull;
+ private string _xmlSingletonSrcFileNameFull;
+ private string _xslSrcFileNameFull;
+ private string _xslPassthroughSrcFileNameFull;
#endregion Private Instance Fields
@@ -66,7 +70,8 @@ public class StyleTaskTest : BuildTestBase {
</cd>
</catalog>";
- private const string _xslSrcFile = @"<?xml version=""1.0"" encoding=""ISO-8859-1""?>
+ private const string _xslSrcFile =
+ @"<?xml version=""1.0"" encoding=""ISO-8859-1""?>
<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">
<xsl:template match=""/"">
@@ -88,9 +93,36 @@ public class StyleTaskTest : BuildTestBase {
</body>
</html>
</xsl:template>
-
- </xsl:stylesheet>";
-
+ </xsl:stylesheet>";
+
+ /// <summary>
+ /// A simple xml input file that includes a singleton tag for passthrough testing (see XSL below)
+ /// </summary>
+ private const string _xmlSingletonSrcFile =
+ @"<roleManager defaultProvider=""sampleprovider"">
+ <providers>
+ <clear />
+ <add name=""samplename"" type=""sampletype"" />
+ </providers>
+ </roleManager>";
+
+ /// <summary>
+ /// A passthrough transform, similar to those used for config file transforms (e.g., XDT)
+ /// This is to make sure that MS-sensitive singleton elements are properly maintained during passthrough
+ /// </summary>
+ private const string _xslPassthroughSrcFile = @"
+ <xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">
+ <xsl:output method=""xml"" indent=""yes"" encoding=""UTF-8""/>
+ <!-- copy entire source -->
+ <xsl:template match=""@* | node()"">
+ <xsl:copy>
+ <xsl:apply-templates select=""@* | node()""/>
+ </xsl:copy>
+ </xsl:template>
+ <xsl:template match=""roleManager/providers/add[@name='samplename']/@type"">
+ <xsl:attribute name=""type"">xslttype</xsl:attribute>
+ </xsl:template>
+ </xsl:stylesheet>";
#endregion Private Static Fields
#region Override implementation of BuildTestBase
@@ -101,9 +133,13 @@ public class StyleTaskTest : BuildTestBase {
_xmlSrcFileNameFull = Path.Combine(TempDirName, _xmlSrcFileName + "." + _xmlSrcFileExtension);
TempFile.CreateWithContents(_xmlSrcFile, _xmlSrcFileNameFull);
_xmlSrcFile2NameFull = Path.Combine(TempDirName, _xmlSrcFile2Name + "." + _xmlSrcFileExtension);
- TempFile.CreateWithContents(_xmlSrcFile, _xmlSrcFile2NameFull);
- _xslSrcFileNameFull = Path.Combine(TempDirName, _xslSrcFileName + "." + _xslSrcFileExtension);
- TempFile.CreateWithContents(_xslSrcFile, _xslSrcFileNameFull);
+ TempFile.CreateWithContents(_xmlSrcFile, _xmlSrcFile2NameFull);
+ _xmlSingletonSrcFileNameFull = Path.Combine(TempDirName, _xmlSingletonFileName + "." + _xmlSrcFileExtension);
+ TempFile.CreateWithContents(_xmlSingletonSrcFile, _xmlSingletonSrcFileNameFull);
+ _xslSrcFileNameFull = Path.Combine(TempDirName, _xslSrcFileName + "." + _xslSrcFileExtension);
+ TempFile.CreateWithContents(_xslSrcFile, _xslSrcFileNameFull);
+ _xslPassthroughSrcFileNameFull = Path.Combine(TempDirName, _xslPassthroughSrcFileName + "." + _xslSrcFileExtension);
+ TempFile.CreateWithContents(_xslPassthroughSrcFile, _xslPassthroughSrcFileNameFull);
}
#endregion Override implementation of BuildTestBase
@@ -396,8 +432,28 @@ public class StyleTaskTest : BuildTestBase {
Assert.IsNotNull(textNode, "XPath expression \"//text/text()\" did not result in a matching node: " + xmlDoc.OuterXml);
Assert.AreEqual("This is written by included template.", textNode.Value);
}
- }
-
+ }
+
+ [Test]
+ public void TransformEngineTests() {
+ // Old engine (XslTransform) would inappropriately convert singleton tags to start/end pairs.
+ // This would cause errors with sensitive readers like ConfigurationManager.AppSettings
+ // With new engine (XslCompiledTransform), singleton tag is preserved
+ // See Github Issue 17 for details (https://github.com/nant/nant/issues/17)
+ string expected = @"<clear />";
+
+ string outputFile = Path.Combine(TempDirName, string.Format(@"{0}.{1}", _xmlSingletonFileName, _outputFileExtension));
+ RunBuild(String.Format(CultureInfo.InvariantCulture, _projectXml, _xmlSingletonSrcFileNameFull, outputFile, _xslPassthroughSrcFileNameFull));
+
+ // ensure output file contains expected content
+ using (StreamReader sr = new StreamReader(File.OpenRead(outputFile))) {
+ string result = sr.ReadToEnd();
+ string msg = string.Format(@"Output file {0} must contain '{1}', contents: {2}", outputFile, expected, result);
+ Assert.IsTrue(result.Contains(expected), msg);
+ }
+ }
+
#endregion Public Instance Methods
+
}
}

No commit comments for this range

Something went wrong with that request. Please try again.