You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(174) |
Nov
(85) |
Dec
(14) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(56) |
Feb
|
Mar
|
Apr
|
May
(4) |
Jun
(1) |
Jul
(132) |
Aug
(5) |
Sep
|
Oct
(314) |
Nov
(133) |
Dec
(18) |
2006 |
Jan
(6) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Oleg T. <he...@us...> - 2005-11-21 21:29:15
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Common/XPath In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15791/v2/src/Exslt/Common/XPath Removed Files: .cvsignore Log Message: --- .cvsignore DELETED --- |
From: Oleg T. <he...@us...> - 2005-11-21 21:29:15
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15791/v2/src/Exslt Modified Files: Exslt.csproj Log Message: Index: Exslt.csproj =================================================================== RCS file: /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Exslt.csproj,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Exslt.csproj 21 Nov 2005 21:21:38 -0000 1.8 +++ Exslt.csproj 21 Nov 2005 21:28:54 -0000 1.9 @@ -73,32 +73,12 @@ <Reference Include="System"> <Name>System</Name> </Reference> - <Reference Include="System.Data"> - <Name>System.Data</Name> - </Reference> - <Reference Include="System.Drawing"> - <Name>System.Drawing</Name> - </Reference> - <Reference Include="System.Web"> - <Name>System.Web</Name> - </Reference> - <Reference Include="System.Windows.Forms"> - <Name>System.Windows.Forms</Name> - </Reference> + <Reference Include="System.Web" /> <Reference Include="System.Xml"> <Name>System.XML</Name> </Reference> </ItemGroup> <ItemGroup> - <Compile Include="..\..\..\..\Common\v2\src\SR.cs"> - <Link>Common\XPath\SR.cs</Link> - </Compile> - <Compile Include="..\..\..\..\Common\v2\src\XPath\EmptyXPathNodeIterator.cs"> - <Link>Common\XPath\EmptyXPathNodeIterator.cs</Link> - </Compile> - <Compile Include="..\..\..\..\Common\v2\src\XPath\XPathNavigatorIterator.cs"> - <Link>Common\XPath\XPathNavigatorIterator.cs</Link> - </Compile> <Compile Include="AssemblyInfo.cs"> <SubType>Code</SubType> </Compile> @@ -159,14 +139,12 @@ <Compile Include="Xsl\IXmlTransform.cs" /> <Compile Include="Xsl\MvpXslTransform.cs" /> <Compile Include="Xsl\XslReader.cs" /> - <Content Include="Makefile" /> </ItemGroup> <ItemGroup> - <EmbeddedResource Include="..\..\..\..\Common\v2\src\SR.resx"> - <Link>Common\XPath\SR.resx</Link> - <DependentUpon>SR.cs</DependentUpon> - <SubType>Designer</SubType> - </EmbeddedResource> + <ProjectReference Include="..\..\..\..\Common\v2\src\Common.csproj"> + <Project>{12B8D3E3-4362-4E91-A3D2-37473083B47A}</Project> + <Name>Common</Name> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <PropertyGroup> |
From: Oleg T. <he...@us...> - 2005-11-21 21:21:47
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Xsl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14063/v2/src/Exslt/Xsl Added Files: IXmlTransform.cs MvpXslTransform.cs XslReader.cs Log Message: --- NEW FILE: IXmlTransform.cs --- #region using using System; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; #endregion namespace Mvp.Xml.Common.Xsl { /// <summary> /// New experimental generic XML transform interface. Defines an API for /// transforming <see cref="XmlInput"/> into <see cref="XmlOutput"/>. /// </summary> public interface IXmlTransform { /// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlOutput"/>. /// </summary> /// <param name="defaulDocument">Default input XML document</param> /// <param name="args">Parameters</param> /// <param name="output">Represents the transformation's output</param> void Transform(XmlInput defaulDocument, XsltArgumentList args, XmlOutput output); /// <summary> /// Defines default output settings. /// </summary> XmlWriterSettings OutputSettings { get; } } /// <summary> /// XmlInput class represents generic XML input to a trasnformation. The actual /// XML to be transformed can be provided as string URI, <see cref="Stream"/>, /// <see cref="TextReader"/>, <see cref="XmlReader"/> or <see cref="IXPathNavigable"/>. /// Optional <see cref="XmlResolver"/> is used to resolve external references when /// loading input XML document and URIs in a "document()" function calls during /// transformation. /// </summary> public class XmlInput { internal object source ; internal XmlResolver resolver; /// <summary> /// Creates new XmlInput object for an XML document provided as an /// <see cref="XmlReader"/>. Also registers an <see cref="XmlResolver"/> to be used /// for resolving external references in the XML document and document() function. /// </summary> /// <param name="reader">Input XML document</param> /// <param name="resolver"><see cref="XmlResolver"/> to resolve external references</param> public XmlInput(XmlReader reader, XmlResolver resolver) { this.source = reader; this.resolver = resolver; } /// <summary> /// Creates new XmlInput object for an XML document provided as a /// <see cref="TextReader"/>. Also registers an <see cref="XmlResolver"/> to be used /// for resolving external references in the XML document and document() function. /// </summary> /// <param name="reader">Input XML document</param> /// <param name="resolver"><see cref="XmlResolver"/> to resolve external references</param> public XmlInput(TextReader reader, XmlResolver resolver) { this.source = reader; this.resolver = resolver; } /// <summary> /// Creates new XmlInput object for an XML document provided as a /// <see cref="Stream"/>. Also registers an <see cref="XmlResolver"/> to be used /// for resolving external references in the XML document and document() function. /// </summary> /// <param name="stream">Input XML document</param> /// <param name="resolver"><see cref="XmlResolver"/> to resolve external references</param> public XmlInput(Stream stream, XmlResolver resolver) { this.source = stream; this.resolver = resolver; } /// <summary> /// Creates new XmlInput object for an XML document provided as an URI. /// Also registers an <see cref="XmlResolver"/> to be used /// for resolving external references in the XML document and document() function. /// </summary> /// <param name="uri">Input XML document</param> /// <param name="resolver"><see cref="XmlResolver"/> to resolve external references</param> public XmlInput(String uri , XmlResolver resolver) { this.source = uri ; this.resolver = resolver; } /// <summary> /// Creates new XmlInput object for an XML document provided as an /// <see cref="IXPathNavigable"/>. Also registers an <see cref="XmlResolver"/> to be used /// for resolving document() function. /// </summary> /// <param name="nav">Input XML document</param> /// <param name="resolver"><see cref="XmlResolver"/> to resolve external references</param> public XmlInput(IXPathNavigable nav , XmlResolver resolver) { this.source = nav ; this.resolver = resolver; } /// <summary> /// Creates new XmlInput object for an XML document provided as an /// <see cref="XmlReader"/>. /// </summary> /// <param name="reader">Input XML document</param> public XmlInput(XmlReader reader) : this(reader, new DefaultXmlResolver()) {} /// <summary> /// Creates new XmlInput object for an XML document provided as a /// <see cref="TextReader"/>. /// </summary> /// <param name="reader">Input XML document</param> public XmlInput(TextReader reader) : this(reader, new DefaultXmlResolver()) {} /// <summary> /// Creates new XmlInput object for an XML document provided as a /// <see cref="Stream"/>. /// </summary> /// <param name="stream">Input XML document</param> public XmlInput(Stream stream) : this(stream, new DefaultXmlResolver()) {} /// <summary> /// Creates new XmlInput object for an XML document provided as an URI. /// </summary> /// <param name="uri">Input XML document</param> public XmlInput(String uri ) : this(uri , new DefaultXmlResolver()) {} /// <summary> /// Creates new XmlInput object for an XML document provided as an /// <see cref="IXPathNavigable"/>. /// </summary> /// <param name="nav">Input XML document</param> public XmlInput(IXPathNavigable nav ) : this(nav , new DefaultXmlResolver()) {} // We can add set of implicit constructors. // I am not shre that this will be for good, so I commented them for now. //public static implicit operator XmlInput(XmlReader reader) { return new XmlInput(reader); } //public static implicit operator XmlInput(TextReader reader) { return new XmlInput(reader); } //public static implicit operator XmlInput(Stream stream) { return new XmlInput(stream); } //public static implicit operator XmlInput(String uri ) { return new XmlInput(uri ); } //public static implicit operator XmlInput(XPathNavigator nav ) { return new XmlInput(nav ); } // the trick doesn't work with interfaces } /// <summary> /// XmlOutput class represents generic XML transformation output. An output XML /// can be written to an URI, <see cref="Stream"/>, <see cref="TextWriter"/> or /// <see cref="XmlWriter"/>. /// </summary> public class XmlOutput { internal object destination; /// <summary> /// Creates new XmlOutput object over an <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">An <see cref="XmlWriter"/> to write output to</param> public XmlOutput(XmlWriter writer) { this.destination = writer; } /// <summary> /// Creates new XmlOutput object over a <see cref="TextWriter"/>. /// </summary> /// <param name="writer">A <see cref="TextWriter"/> to write output to</param> public XmlOutput(TextWriter writer) { this.destination = writer; } /// <summary> /// Creates new XmlOutput object over a <see cref="Stream"/>. /// </summary> /// <param name="stream">A <see cref="Stream"/> to write output to</param> public XmlOutput(Stream stream ) { this.destination = stream ; } /// <summary> /// Creates new XmlOutput object over an URI. /// </summary> /// <param name="uri">An URI to write output to</param> public XmlOutput(String uri ) { this.destination = uri ; } // We will add overrides with XmlOutputResolver here later to support multiple output documents (<xsl:result-document>) } /// <summary> /// XmlUrlResolver wrapper allowing us to recognize the case when no /// XmlResolver was passed. /// </summary> internal class DefaultXmlResolver : XmlUrlResolver { public DefaultXmlResolver() : base() {} } } --- NEW FILE: MvpXslTransform.cs --- #region using using System; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.Reflection; using System.CodeDom.Compiler; using Mvp.Xml.Exslt; #endregion namespace Mvp.Xml.Common.Xsl { /// <summary> /// <para>MvpXslTransform class extends capabilities of the <see cref="XslCompiledTransform"/> /// class by adding support for transforming into <see cref="XmlReader"/>, /// vast collection of EXSLT extention functions, multiple outputs and /// transforming of <see cref="IXPathNavigable"/> along with <see cref="XmlResolver"/>. /// Also MvpXslTransform class provides new clean experimental XSL transformation API /// by introducing concepts of <see cref="IXmlTransform"/> interface, <see cref="XmlInput"/> /// and <see cref="XmlOutput"/>.</para> /// </summary> /// <remarks><para>MvpXslTransform class is thread-safe for Transorm() methods. I.e. /// once MvpXslTransform object is loaded, you can safely call its Transform() methods /// in multiple threads simultaneously.</para> /// <para>MvpXslTransform supports EXSLT extension functions from the following namespaces: /// * http://exslt.org/common /// * http://exslt.org/dates-and-times /// * http://exslt.org/math /// * http://exslt.org/random /// * http://exslt.org/regular-expressions /// * http://exslt.org/sets /// * http://exslt.org/strings /// * http://gotdotnet.com/exslt/dates-and-times /// * http://gotdotnet.com/exslt/math /// * http://gotdotnet.com/exslt/regular-expressions /// * http://gotdotnet.com/exslt/sets /// * http://gotdotnet.com/exslt/strings /// * http://gotdotnet.com/exslt/dynamic</para> /// <para>Multioutput (<exsl:document> element) is turned off by default and can /// be turned on using MultiOutput property. Note, that multioutput is not supported /// when transfomation is done to <see cref="XmlWriter"/> or <see cref="XmlReader"/>.</para> /// <para>MvpXslTransform uses XSLT extension objects and reflection and so using /// it requires FullTrust security level.</para> /// </remarks> public class MvpXslTransform : IXmlTransform { private XslCompiledTransform compiledTransform; private object sync = new object(); private ExsltFunctionNamespace supportedFunctions = ExsltFunctionNamespace.All; private bool multiOutput; #region ctors /// <summary> /// Initializes a new instance of the MvpXslTransform class. /// </summary> public MvpXslTransform() { this.compiledTransform = new XslCompiledTransform(); } /// <summary> /// Initializes a new instance of the MvpXslTransform /// class with the specified debug setting. /// </summary> public MvpXslTransform(bool debug) { this.compiledTransform = new XslCompiledTransform(debug); } #endregion #region Load() method overloads /// <summary> /// Loads and compiles the style sheet contained in the <see cref="IXPathNavigable"/> object. /// See also <see cref="XslCompiledTransform(IXPathNavigable)"/>. /// </summary> /// <param name="stylesheet">An object implementing the <see cref="IXPathNavigable"/> interface. /// In the Microsoft .NET Framework, this can be either an <see cref="XmlNode"/> (typically an <see cref="XmlDocument"/>), /// or an <see cref="XPathDocument"/> containing the style sheet.</param> public void Load(IXPathNavigable stylesheet) { this.compiledTransform.Load(stylesheet); } /// <summary> /// Loads and compiles the style sheet located at the specified URI. /// See also <see cref="XslCompiledTransform(String)"/>. /// </summary> /// <param name="stylesheetUri">The URI of the style sheet.</param> public void Load(string stylesheetUri) { this.compiledTransform.Load(stylesheetUri); } /// <summary> /// Compiles the style sheet contained in the <see cref="XmlReader"/>. /// See also <see cref="XslCompiledTransform(XmlReader)"/>. /// </summary> /// <param name="stylesheet">An <see cref="XmlReader"/> containing the style sheet.</param> public void Load(XmlReader stylesheet) { this.compiledTransform.Load(stylesheet); } /// <summary> /// Compiles the XSLT style sheet contained in the <see cref="IXPathNavigable"/>. /// The <see cref="XmlResolver"/> resolves any XSLT <c>import</c> or <c>include</c> elements and the /// XSLT settings determine the permissions for the style sheet. /// See also <see cref="XslCompiledTransform(IXPathNavigable, XsltSettings, XmlResolver)"/>. /// </summary> /// <param name="stylesheet">An object implementing the <see cref="IXPathNavigable"/> interface. /// In the Microsoft .NET Framework, this can be either an <see cref="XmlNode"/> (typically an <see cref="XmlDocument"/>), /// or an <see cref="XPathDocument"/> containing the style sheet.</param> /// <param name="settings">The <see cref="XsltSettings"/> to apply to the style sheet. /// If this is a null reference (Nothing in Visual Basic), the <see cref="XsltSettings.Default"> setting is applied.</param> /// <param name="stylesheetResolver">The <see cref="XmlResolver"/> used to resolve any /// style sheets referenced in XSLT <c>import</c> and <c>include</c> elements. If this is a /// null reference (Nothing in Visual Basic), external resources are not resolved.</param> public void Load(IXPathNavigable stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheet, settings, stylesheetResolver); } /// <summary> /// Loads and compiles the XSLT style sheet specified by the URI. /// The <see cref="XmlResolver"/> resolves any XSLT <c>import</c> or <c>include</c> elements and the /// XSLT settings determine the permissions for the style sheet. /// See also <see cref="XslCompiledTransform(string, XsltSettings, XmlResolver)"/>. /// </summary> /// <param name="stylesheetUri">The URI of the style sheet.</param> /// <param name="settings">The <see cref="XsltSettings"/> to apply to the style sheet. /// If this is a null reference (Nothing in Visual Basic), the <see cref="XsltSettings.Default"> setting is applied.</param> /// <param name="stylesheetResolver">The <see cref="XmlResolver"/> used to resolve any /// style sheets referenced in XSLT <c>import</c> and <c>include</c> elements. If this is a /// null reference (Nothing in Visual Basic), external resources are not resolved.</param> public void Load(string stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheetUri, settings, stylesheetResolver); } /// <summary> /// Compiles the XSLT style sheet contained in the <see cref="XmlReader"/>. /// The <see cref="XmlResolver"/> resolves any XSLT <c>import</c> or <c>include</c> elements and the /// XSLT settings determine the permissions for the style sheet. /// See also <see cref="XslCompiledTransform(XmlReader, XsltSettings, XmlResolver)"/>. /// </summary> /// <param name="stylesheet">The <see cref="XmlReader"/> containing the style sheet.</param> /// <param name="settings">The <see cref="XsltSettings"/> to apply to the style sheet. /// If this is a null reference (Nothing in Visual Basic), the <see cref="XsltSettings.Default"> setting is applied.</param> /// <param name="stylesheetResolver">The <see cref="XmlResolver"/> used to resolve any /// style sheets referenced in XSLT <c>import</c> and <c>include</c> elements. If this is a /// null reference (Nothing in Visual Basic), external resources are not resolved.</param> public void Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheet, settings, stylesheetResolver); } #endregion #region public properties /// <summary> /// Bitwise enumeration used to specify which EXSLT functions should be accessible to /// the MvpXslTransform object. The default value is ExsltFunctionNamespace.All /// </summary> public ExsltFunctionNamespace SupportedFunctions { set { if (Enum.IsDefined(typeof(ExsltFunctionNamespace), value)) supportedFunctions = value; } get { return supportedFunctions; } } /// <summary> /// Boolean flag used to specify whether multiple output (via exsl:document) is /// supported. /// Note: This property is ignored (hence multiple output is not supported) when /// transformation is done to XmlReader or XmlWriter (use overloaded method, /// which transforms to MultiXmlTextWriter instead). /// Note: Because of some restrictions and slight overhead this feature is /// disabled by default. If you need multiple output support, set this property to /// true before the Transform() call. /// </summary> public bool MultiOutput { get { return multiOutput; } set { multiOutput = value; } } /// <summary> /// Gets the TempFileCollection that contains the temporary files generated /// on disk after a successful call to the Load method. /// </summary> public TempFileCollection TemporaryFiles { get { return this.compiledTransform.TemporaryFiles; } } #endregion #region IXmlTransform impl /// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlOutput"/>. /// The <see cref="XsltArgumentList"/> provides additional runtime arguments. /// </summary> /// <param name="input">Default input XML document.</param> /// <param name="arguments">An <see cref="XsltArgumentList"/> containing the namespace-qualified /// arguments used as input to the transform. This value can be a null reference (Nothing in Visual Basic).</param> /// <param name="output">Represents the transformation's output.</param> public void Transform(XmlInput input, XsltArgumentList arguments, XmlOutput output) { if (input == null) throw new ArgumentNullException("defaltDocument"); XmlWriter xmlWriter = output.destination as XmlWriter; bool closeWriter = false; if (xmlWriter == null) { closeWriter = true; while (true) { TextWriter txtWriter = output.destination as TextWriter; if (txtWriter != null) { if (multiOutput) { xmlWriter = new MultiXmlTextWriter(txtWriter); } else { xmlWriter = XmlWriter.Create(txtWriter, this.compiledTransform.OutputSettings); } break; } Stream strm = output.destination as Stream; if (strm != null) { if (multiOutput) { xmlWriter = new MultiXmlTextWriter(strm, this.compiledTransform.OutputSettings.Encoding); } else { xmlWriter = XmlWriter.Create(strm, this.compiledTransform.OutputSettings); } break; } String str = output.destination as String; if (str != null) { if (multiOutput) { xmlWriter = new MultiXmlTextWriter(str, this.compiledTransform.OutputSettings.Encoding); } else { XmlWriterSettings outputSettings = this.compiledTransform.OutputSettings.Clone(); outputSettings.CloseOutput = true; // BugBug: We should read doc before creating output file in case they are the same xmlWriter = XmlWriter.Create(str, outputSettings); } break; } throw new Exception("Unexpected XmlOutput"); } } try { TransformToWriter(input, arguments, xmlWriter); } finally { if (closeWriter) { xmlWriter.Close(); } } } /// <summary> /// Gets an <see cref="XmlWriterSettings"/> object that contains the output /// information derived from the xsl:output element of the style sheet. /// </summary> public XmlWriterSettings OutputSettings { get { if (this.compiledTransform != null) { return this.compiledTransform.OutputSettings; } else { return new XmlWriterSettings(); } } } #endregion #region additional Transform() methods /// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlReader"/>. /// </summary> /// <param name="input">Default input XML document</param> /// <param name="arguments">An <see cref="XsltArgumentList"/> containing the namespace-qualified /// arguments used as input to the transform. This value can be a null reference (Nothing in Visual Basic).</param> public XmlReader Transform(XmlInput input, XsltArgumentList arguments) { XslReader r = new XslReader(this.compiledTransform); r.StartTransform(input, AddExsltExtensionObjects(arguments)); return r; } #endregion #region private stuff private static XmlReaderSettings DefaultReaderSettings; static MvpXslTransform() { DefaultReaderSettings = new XmlReaderSettings(); DefaultReaderSettings.ProhibitDtd = false; } private XmlReaderSettings GetReaderSettings(XmlInput defaultDocument) { if (defaultDocument.resolver is DefaultXmlResolver) { return DefaultReaderSettings; } else { XmlReaderSettings settings = DefaultReaderSettings.Clone(); settings.XmlResolver = defaultDocument.resolver; return settings; } } private void TransformToWriter(XmlInput defaultDocument, XsltArgumentList xsltArgs, XmlWriter xmlWriter) { XsltArgumentList args = AddExsltExtensionObjects(xsltArgs); XmlReader xmlReader = defaultDocument.source as XmlReader; if (xmlReader != null) { this.compiledTransform.Transform(xmlReader, args, xmlWriter, defaultDocument.resolver); return; } IXPathNavigable nav = defaultDocument.source as IXPathNavigable; if (nav != null) { if (defaultDocument.resolver is DefaultXmlResolver) { this.compiledTransform.Transform(nav, args, xmlWriter); } else { TransformIXPathNavigable(nav, args, xmlWriter, defaultDocument.resolver); } return; } string str = defaultDocument.source as string; if (str != null) { using (XmlReader reader = XmlReader.Create(str, GetReaderSettings(defaultDocument))) { this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver); } return; } Stream strm = defaultDocument.source as Stream; if (strm != null) { using (XmlReader reader = XmlReader.Create(strm, GetReaderSettings(defaultDocument))) { this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver); } return; } TextReader txtReader = defaultDocument.source as TextReader; if (txtReader != null) { using (XmlReader reader = XmlReader.Create(txtReader, GetReaderSettings(defaultDocument))) { this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver); } return; } throw new Exception("Unexpected XmlInput"); } private void TransformIXPathNavigable(IXPathNavigable nav, XsltArgumentList args, XmlWriter xmlWriter, XmlResolver resolver) { object command = this.compiledTransform.GetType().GetField( "command", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this.compiledTransform); MethodInfo executeMethod = command.GetType().GetMethod("Execute", BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(IXPathNavigable), typeof(XmlResolver), typeof(XsltArgumentList), typeof(XmlWriter) }, null); executeMethod.Invoke(command, new object[] { nav, resolver, AddExsltExtensionObjects(args), xmlWriter }); } /// <summary> /// Adds the objects that implement the EXSLT extensions to the provided argument /// list. The extension objects added depend on the value of the SupportedFunctions /// property. /// </summary> /// <param name="list">The argument list</param> /// <returns>An XsltArgumentList containing the contents of the list passed in /// and objects that implement the EXSLT. </returns> /// <remarks>If null is passed in then a new XsltArgumentList is constructed. </remarks> private XsltArgumentList AddExsltExtensionObjects(XsltArgumentList list) { if (list == null) { list = new XsltArgumentList(); } lock (sync) { //remove all our extension objects in case the XSLT argument list is being reused list.RemoveExtensionObject(ExsltNamespaces.Math); list.RemoveExtensionObject(ExsltNamespaces.Random); list.RemoveExtensionObject(ExsltNamespaces.DatesAndTimes); list.RemoveExtensionObject(ExsltNamespaces.RegularExpressions); list.RemoveExtensionObject(ExsltNamespaces.Strings); list.RemoveExtensionObject(ExsltNamespaces.Sets); list.RemoveExtensionObject(ExsltNamespaces.GDNDatesAndTimes); list.RemoveExtensionObject(ExsltNamespaces.GDNMath); list.RemoveExtensionObject(ExsltNamespaces.GDNRegularExpressions); list.RemoveExtensionObject(ExsltNamespaces.GDNSets); list.RemoveExtensionObject(ExsltNamespaces.GDNStrings); list.RemoveExtensionObject(ExsltNamespaces.GDNDynamic); //add extension objects as specified by SupportedFunctions if ((this.SupportedFunctions & ExsltFunctionNamespace.Math) > 0) { list.AddExtensionObject(ExsltNamespaces.Math, new ExsltMath()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.Random) > 0) { list.AddExtensionObject(ExsltNamespaces.Random, new ExsltRandom()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.DatesAndTimes) > 0) { list.AddExtensionObject(ExsltNamespaces.DatesAndTimes, new ExsltDatesAndTimes()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.RegularExpressions) > 0) { list.AddExtensionObject(ExsltNamespaces.RegularExpressions, new ExsltRegularExpressions()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.Strings) > 0) { list.AddExtensionObject(ExsltNamespaces.Strings, new ExsltStrings()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.Sets) > 0) { list.AddExtensionObject(ExsltNamespaces.Sets, new ExsltSets()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNDatesAndTimes) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNDatesAndTimes, new GDNDatesAndTimes()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNMath) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNMath, new GDNMath()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNRegularExpressions) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNRegularExpressions, new GDNRegularExpressions()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNSets) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNSets, new GDNSets()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNStrings) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNStrings, new GDNStrings()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNDynamic) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNDynamic, new GDNDynamic()); } } return list; } #endregion } } --- NEW FILE: XslReader.cs --- #region using using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.Diagnostics; using System.Threading; #endregion namespace Mvp.Xml.Common.Xsl { /// <summary> /// <para>XslReader provides an efficient way to read results of an XSL /// transformation via an <see cref="XmlReader"/> API. Due to /// architectural and performance reasons the <see cref="XslCompiledTransform"/> /// class doesn't support transforming to an <see cref="XmlReader"/> as obsolete [...1065 lines suppressed...] } } public override void Close() { Write(XmlNodeType.None, null, null); lock (this) { Monitor.Pulse(this); } } public override void GetToken(int attNum, out QName name, out string value) { Debug.Assert(0 <= attNum && attNum < readEndPos - readStartPos - 1); XmlNodeType nodeType; XmlToken.Get(ref buffer[(readStartPos + attNum) & mask], out nodeType, out name, out value); Debug.Assert(nodeType == (attNum == 0 ? XmlNodeType.Element : XmlNodeType.Attribute), "We use GetToken() only to access parts of start element tag."); } } #endregion ------------------------------- Supporting classes ------------------------------ } } |
From: Oleg T. <he...@us...> - 2005-11-21 21:21:46
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14063/v2/src/Exslt Modified Files: Exslt.csproj Log Message: Index: Exslt.csproj =================================================================== RCS file: /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Exslt.csproj,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Exslt.csproj 21 Nov 2005 16:21:51 -0000 1.7 +++ Exslt.csproj 21 Nov 2005 21:21:38 -0000 1.8 @@ -156,6 +156,9 @@ <Compile Include="MultiOutput\OutputState.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Xsl\IXmlTransform.cs" /> + <Compile Include="Xsl\MvpXslTransform.cs" /> + <Compile Include="Xsl\XslReader.cs" /> <Content Include="Makefile" /> </ItemGroup> <ItemGroup> |
From: Oleg T. <he...@us...> - 2005-11-21 21:17:17
|
Update of /cvsroot/mvp-xml/Common/v2/src/Xsl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12765/v2/src/Xsl Removed Files: IXmlTransform.cs MvpXslTransform.cs XslReader.cs Log Message: --- IXmlTransform.cs DELETED --- --- MvpXslTransform.cs DELETED --- --- XslReader.cs DELETED --- |
From: Oleg T. <he...@us...> - 2005-11-21 21:17:17
|
Update of /cvsroot/mvp-xml/Common/v2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12765/v2/src Modified Files: Common.csproj Log Message: Index: Common.csproj =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/Common.csproj,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- Common.csproj 19 Nov 2005 22:21:10 -0000 1.13 +++ Common.csproj 21 Nov 2005 21:17:08 -0000 1.14 @@ -75,10 +75,6 @@ <ErrorReport>prompt</ErrorReport> </PropertyGroup> <ItemGroup> - <Reference Include="Mvp.Xml.Exslt, Version=2.0.2148.42146, Culture=neutral, PublicKeyToken=dd92544dc05f5671, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\..\EXSLT\v2\src\Exslt\Mvp.Xml.Exslt.dll</HintPath> - </Reference> <Reference Include="System"> <Name>System</Name> </Reference> @@ -149,9 +145,6 @@ <Compile Include="XPath\XPathVariable.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Xsl\IXmlTransform.cs" /> - <Compile Include="Xsl\MvpXslTransform.cs" /> - <Compile Include="Xsl\XslReader.cs" /> <Content Include="changelog.txt" /> <EmbeddedResource Include="Serialization\PerfCounterInstaller.resx"> <DependentUpon>PerfCounterInstaller.cs</DependentUpon> |
From: Oleg T. <he...@us...> - 2005-11-21 21:11:27
|
Update of /cvsroot/mvp-xml/Global/v2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9631/v2 Modified Files: Global.csproj Log Message: Index: Global.csproj =================================================================== RCS file: /cvsroot/mvp-xml/Global/v2/Global.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Global.csproj 20 Nov 2005 22:02:10 -0000 1.3 +++ Global.csproj 21 Nov 2005 21:11:19 -0000 1.4 @@ -305,6 +305,6 @@ del Mvp.Xml.il del Mvp.Xml.Fixed.il del *.resources -@echo ########### Mvp.Xml Custom Build Event has stopped</PostBuildEvent> +@echo ########### Mvp.Xml Custom Build Event has finished</PostBuildEvent> </PropertyGroup> </Project> \ No newline at end of file |
From: Oleg T. <he...@us...> - 2005-11-21 20:50:07
|
Update of /cvsroot/mvp-xml/Common/v2/test/MvpXslTransformTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3862/v2/test/MvpXslTransformTests Modified Files: MvpXslTransformTests.cs Added Files: exslt-test.xslt Log Message: Index: MvpXslTransformTests.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/test/MvpXslTransformTests/MvpXslTransformTests.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- MvpXslTransformTests.cs 20 Nov 2005 21:56:58 -0000 1.2 +++ MvpXslTransformTests.cs 21 Nov 2005 20:49:52 -0000 1.3 @@ -14,7 +14,7 @@ { byte[] standardResult; byte[] resolverTestStandardResult; - MvpXslTransform xslt, xslt2; + MvpXslTransform xslt, xslt2; XsltArgumentList args; public MvpXslTransformTests() @@ -36,7 +36,7 @@ xslt2.Transform(r2, Arguments, w, new MyXmlResolver()); } w.Close(); - resolverTestStandardResult = ms2.ToArray(); + resolverTestStandardResult = ms2.ToArray(); } private XsltArgumentList Arguments @@ -69,7 +69,7 @@ xslt2.Load("../../MvpXslTransformTests/resolver-test.xslt", XsltSettings.TrustedXslt, null); } return xslt2; - } + } private static void CompareResults(byte[] standard, byte[] test) { @@ -324,7 +324,35 @@ MemoryStream ms = new MemoryStream(); xslt.Transform(input, Arguments, new XmlOutput(ms)); CompareResults(resolverTestStandardResult, ms.ToArray()); - } + } + + [Test] + public void ExsltTest() + { + MvpXslTransform xslt = new MvpXslTransform(); + xslt.Load("../../MvpXslTransformTests/exslt-test.xslt"); + XmlInput input = new XmlInput("../../MvpXslTransformTests/test.xml"); + MemoryStream ms = new MemoryStream(); + xslt.Transform(input, Arguments, new XmlOutput(ms)); + string expected = "<out>3</out>"; + CompareResults(Encoding.ASCII.GetBytes(expected), ms.ToArray()); + } + + [Test] + public void NoExsltTest() + { + MvpXslTransform xslt = new MvpXslTransform(); + xslt.Load("../../MvpXslTransformTests/exslt-test.xslt"); + XmlInput input = new XmlInput("../../MvpXslTransformTests/test.xml"); + MemoryStream ms = new MemoryStream(); + xslt.SupportedFunctions = Mvp.Xml.Exslt.ExsltFunctionNamespace.None; + try + { + xslt.Transform(input, Arguments, new XmlOutput(ms)); + } + catch (XsltException) { return; } + Assert.Fail("Shoudn't be here."); + } } public class MyXmlResolver : XmlUrlResolver --- NEW FILE: exslt-test.xslt --- <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:math="http://exslt.org/math" exclude-result-prefixes="math"> <xsl:output omit-xml-declaration="yes" encoding="ascii"/> <xsl:template match="/"> <out><xsl:value-of select="math:sqrt(9)"/></out> </xsl:template> </xsl:stylesheet> |
From: Oleg T. <he...@us...> - 2005-11-21 20:50:02
|
Update of /cvsroot/mvp-xml/Common/v2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3862/v2/test Modified Files: CommonTest.csproj Log Message: Index: CommonTest.csproj =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/test/CommonTest.csproj,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- CommonTest.csproj 20 Nov 2005 21:56:58 -0000 1.7 +++ CommonTest.csproj 21 Nov 2005 20:49:52 -0000 1.8 @@ -74,6 +74,10 @@ <ErrorReport>prompt</ErrorReport> </PropertyGroup> <ItemGroup> + <Reference Include="Mvp.Xml.Exslt, Version=2.0.2148.42336, Culture=neutral, PublicKeyToken=dd92544dc05f5671, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\EXSLT\v2\src\Exslt\Mvp.Xml.Exslt.dll</HintPath> + </Reference> <Reference Include="nunit.framework"> <Name>nunit.framework</Name> <HintPath>..\..\..\..\..\Program Files\NUnit 2.2\bin\nunit.framework.dll</HintPath> @@ -179,6 +183,7 @@ </Compile> <Compile Include="XslReaderTests\XslReaderTests.cs" /> <Content Include="changelog.txt" /> + <Content Include="MvpXslTransformTests\exslt-test.xslt" /> <Content Include="MvpXslTransformTests\resolver-test.xslt" /> <Content Include="MvpXslTransformTests\test.xml" /> <Content Include="MvpXslTransformTests\test1.xslt" /> |
From: Oleg T. <he...@us...> - 2005-11-21 20:31:17
|
Update of /cvsroot/mvp-xml/EXSLT/v2/test/ExsltTest/tests/EXSLT/Strings In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32253/v2/test/ExsltTest/tests/EXSLT/Strings Removed Files: tmp0000.xml Log Message: --- tmp0000.xml DELETED --- |
From: Oleg T. <he...@us...> - 2005-11-21 16:31:52
|
Update of /cvsroot/mvp-xml/XPointer/v2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31676/v2/src Modified Files: XPointer.csproj Log Message: Index: XPointer.csproj =================================================================== RCS file: /cvsroot/mvp-xml/XPointer/v2/src/XPointer.csproj,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- XPointer.csproj 28 Oct 2005 21:51:34 -0000 1.5 +++ XPointer.csproj 21 Nov 2005 16:31:45 -0000 1.6 @@ -89,6 +89,9 @@ <Link>Common\SR.cs</Link> <SubType>Code</SubType> </Compile> + <Compile Include="..\..\..\Common\v2\src\XmlBaseAwareXmlTextReader.cs"> + <Link>Common\XPath\XmlBaseAwareXmlTextReader.cs</Link> + </Compile> <Compile Include="..\..\..\Common\v2\src\XmlNamespaces.cs"> <Link>Common\XmlNamespaces.cs</Link> <SubType>Code</SubType> @@ -109,6 +112,9 @@ <Link>Common\XPath\IHasXPathNavigator.cs</Link> <SubType>Code</SubType> </Compile> + <Compile Include="..\..\..\Common\v2\src\XPath\SubtreeeXPathNavigator.cs"> + <Link>Common\XPath\SubtreeeXPathNavigator.cs</Link> + </Compile> <Compile Include="..\..\..\Common\v2\src\XPath\XPathCache.cs"> <Link>Common\XPath\XPathCache.cs</Link> <SubType>Code</SubType> |
From: Oleg T. <he...@us...> - 2005-11-21 16:22:18
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29260/v2/src/Exslt Modified Files: Exslt.csproj Removed Files: Makefile Log Message: --- Makefile DELETED --- Index: Exslt.csproj =================================================================== RCS file: /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Exslt.csproj,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Exslt.csproj 18 Nov 2005 21:24:46 -0000 1.6 +++ Exslt.csproj 21 Nov 2005 16:21:51 -0000 1.7 @@ -70,10 +70,6 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="Mvp.Xml.Common, Version=2.0.2128.41359, Culture=neutral, PublicKeyToken=dd92544dc05f5671, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\..\..\Common\v2\src\bin\Debug\Mvp.Xml.Common.dll</HintPath> - </Reference> <Reference Include="System"> <Name>System</Name> </Reference> @@ -94,6 +90,15 @@ </Reference> </ItemGroup> <ItemGroup> + <Compile Include="..\..\..\..\Common\v2\src\SR.cs"> + <Link>Common\XPath\SR.cs</Link> + </Compile> + <Compile Include="..\..\..\..\Common\v2\src\XPath\EmptyXPathNodeIterator.cs"> + <Link>Common\XPath\EmptyXPathNodeIterator.cs</Link> + </Compile> + <Compile Include="..\..\..\..\Common\v2\src\XPath\XPathNavigatorIterator.cs"> + <Link>Common\XPath\XPathNavigatorIterator.cs</Link> + </Compile> <Compile Include="AssemblyInfo.cs"> <SubType>Code</SubType> </Compile> @@ -154,7 +159,11 @@ <Content Include="Makefile" /> </ItemGroup> <ItemGroup> - <Folder Include="Xsl\" /> + <EmbeddedResource Include="..\..\..\..\Common\v2\src\SR.resx"> + <Link>Common\XPath\SR.resx</Link> + <DependentUpon>SR.cs</DependentUpon> + <SubType>Designer</SubType> + </EmbeddedResource> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <PropertyGroup> @@ -162,6 +171,16 @@ </PreBuildEvent> <PostBuildEvent>@echo ########### Setting environment variables call "$(DevEnvDir)..\Tools\vsvars32.bat" -nmake</PostBuildEvent> +@echo ########### Disassembing... +ildasm Mvp.Xml.Exslt.dll /out=Mvp.Xml.Exslt.il /nobar +@echo ########### Renaming methods... +MethodRenamer.exe Mvp.Xml.Exslt.il Mvp.Xml.Exslt.Fixed.il +@echo ########### Assembling library back... +ilasm Mvp.Xml.Exslt.Fixed.il /RESOURCE=Mvp.Xml.Exslt.res /DLL /OUTPUT=Mvp.Xml.Exslt.dll /KEY=../../../../Global/mvp-xml.snk +@echo ########### Cleaning... +del Mvp.Xml.Exslt.res +del Mvp.Xml.Exslt.il +del Mvp.Xml.Exslt.Fixed.il +del Mvp.Xml.Common.SR.resources</PostBuildEvent> </PropertyGroup> </Project> \ No newline at end of file |
From: Oleg T. <he...@us...> - 2005-11-21 16:22:00
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Common/XPath In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29260/v2/src/Exslt/Common/XPath Added Files: .cvsignore Log Message: --- NEW FILE: .cvsignore --- bin obj *.user *.suo *.vspscc *.pdb *.dll |
From: Oleg T. <he...@us...> - 2005-11-21 16:21:29
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Common/XPath In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29109/XPath Log Message: Directory /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Common/XPath added to the repository |
From: Oleg T. <he...@us...> - 2005-11-21 16:21:20
|
Update of /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29079/Common Log Message: Directory /cvsroot/mvp-xml/EXSLT/v2/src/Exslt/Common added to the repository |
From: Oleg T. <he...@us...> - 2005-11-21 15:48:29
|
Update of /cvsroot/mvp-xml/Global In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21530 Removed Files: Mvp.Xml.sln Log Message: --- Mvp.Xml.sln DELETED --- |
From: Oleg T. <he...@us...> - 2005-11-20 22:02:18
|
Update of /cvsroot/mvp-xml/Global/v2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21972/v2 Modified Files: Global.csproj Log Message: Index: Global.csproj =================================================================== RCS file: /cvsroot/mvp-xml/Global/v2/Global.csproj,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Global.csproj 17 Nov 2005 21:56:51 -0000 1.2 +++ Global.csproj 20 Nov 2005 22:02:10 -0000 1.3 @@ -120,6 +120,15 @@ <Compile Include="..\..\Common\v2\src\XPath\XPathVariable.cs"> <Link>Common\XPath\XPathVariable.cs</Link> </Compile> + <Compile Include="..\..\Common\v2\src\Xsl\IXmlTransform.cs"> + <Link>Common\Xsl\IXmlTransform.cs</Link> + </Compile> + <Compile Include="..\..\Common\v2\src\Xsl\MvpXslTransform.cs"> + <Link>Common\Xsl\MvpXslTransform.cs</Link> + </Compile> + <Compile Include="..\..\Common\v2\src\Xsl\XslReader.cs"> + <Link>Common\Xsl\XslReader.cs</Link> + </Compile> <Compile Include="..\..\EXSLT\v2\src\Exslt\ExsltContext.cs"> <Link>EXSLT\ExsltContext.cs</Link> </Compile> @@ -174,15 +183,6 @@ <Compile Include="..\..\EXSLT\v2\src\Exslt\MultiOutput\OutputState.cs"> <Link>EXSLT\MultiOutput\OutputState.cs</Link> </Compile> - <Compile Include="..\..\EXSLT\v2\src\Exslt\Xsl\IXmlTransform.cs"> - <Link>EXSLT\Xsl\IXmlTransform.cs</Link> - </Compile> - <Compile Include="..\..\EXSLT\v2\src\Exslt\Xsl\MvpXslTransform.cs"> - <Link>EXSLT\Xsl\MvpXslTransform.cs</Link> - </Compile> - <Compile Include="..\..\EXSLT\v2\src\Exslt\Xsl\XslReader.cs"> - <Link>EXSLT\Xsl\XslReader.cs</Link> - </Compile> <Compile Include="..\..\XInclude\v2\src\SR.cs"> <Link>XInclude\SR.cs</Link> </Compile> @@ -257,7 +257,6 @@ <None Include="Common\XPath\.cvsignore" /> <None Include="EXSLT\.cvsignore" /> <None Include="EXSLT\MultiOutput\.cvsignore" /> - <None Include="EXSLT\Xsl\.cvsignore" /> <None Include="XInclude\.cvsignore" /> <None Include="XPointer\.cvsignore" /> </ItemGroup> |
From: Oleg T. <he...@us...> - 2005-11-20 22:02:18
|
Update of /cvsroot/mvp-xml/Global/v2/Common/Xsl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21972/v2/Common/Xsl Added Files: .cvsignore Log Message: --- NEW FILE: .cvsignore --- bin obj *.user *.suo |
From: Oleg T. <he...@us...> - 2005-11-20 22:01:17
|
Update of /cvsroot/mvp-xml/Global/v2/Common/Xsl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21696/Xsl Log Message: Directory /cvsroot/mvp-xml/Global/v2/Common/Xsl added to the repository |
From: Oleg T. <he...@us...> - 2005-11-20 21:57:06
|
Update of /cvsroot/mvp-xml/Common/v2/src/Xsl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20469/v2/src/Xsl Modified Files: MvpXslTransform.cs Log Message: Index: MvpXslTransform.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/Xsl/MvpXslTransform.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- MvpXslTransform.cs 19 Nov 2005 22:21:10 -0000 1.6 +++ MvpXslTransform.cs 20 Nov 2005 21:56:58 -0000 1.7 @@ -74,20 +74,43 @@ #region Load() method overloads - /// <summary> Loads the XSLT stylesheet contained in the IXPathNavigable</summary> - public void Load(IXPathNavigable ixn) { this.compiledTransform.Load(ixn); } + /// <summary> + /// Loads and compiles the style sheet contained in the <see cref="IXPathNavigable"/> object. + /// See also <see cref="XslCompiledTransform(IXPathNavigable)"/>. + /// </summary> + /// <param name="stylesheet">An object implementing the <see cref="IXPathNavigable"/> interface. + /// In the Microsoft .NET Framework, this can be either an <see cref="XmlNode"/> (typically an <see cref="XmlDocument"/>), + /// or an <see cref="XPathDocument"/> containing the style sheet.</param> + public void Load(IXPathNavigable stylesheet) { this.compiledTransform.Load(stylesheet); } - /// <summary> Loads the XSLT stylesheet specified by a URI</summary> + /// <summary> + /// Loads and compiles the style sheet located at the specified URI. + /// See also <see cref="XslCompiledTransform(String)"/>. + /// </summary> + /// <param name="stylesheetUri">The URI of the style sheet.</param> public void Load(string stylesheetUri) { this.compiledTransform.Load(stylesheetUri); } - /// <summary> Loads the XSLT stylesheet contained in the XmlReader</summary> - public void Load(XmlReader reader) { this.compiledTransform.Load(reader); } + /// <summary> + /// Compiles the style sheet contained in the <see cref="XmlReader"/>. + /// See also <see cref="XslCompiledTransform(XmlReader)"/>. + /// </summary> + /// <param name="stylesheet">An <see cref="XmlReader"/> containing the style sheet.</param> + public void Load(XmlReader stylesheet) { this.compiledTransform.Load(stylesheet); } /// <summary> - /// Compiles the XSLT style sheet contained in the IXPathNavigable. - /// The XmlResolver resolves any XSLT import or include elements and the + /// Compiles the XSLT style sheet contained in the <see cref="IXPathNavigable"/>. + /// The <see cref="XmlResolver"/> resolves any XSLT <c>import</c> or <c>include</c> elements and the /// XSLT settings determine the permissions for the style sheet. - /// </summary> + /// See also <see cref="XslCompiledTransform(IXPathNavigable, XsltSettings, XmlResolver)"/>. + /// </summary> + /// <param name="stylesheet">An object implementing the <see cref="IXPathNavigable"/> interface. + /// In the Microsoft .NET Framework, this can be either an <see cref="XmlNode"/> (typically an <see cref="XmlDocument"/>), + /// or an <see cref="XPathDocument"/> containing the style sheet.</param> + /// <param name="settings">The <see cref="XsltSettings"/> to apply to the style sheet. + /// If this is a null reference (Nothing in Visual Basic), the <see cref="XsltSettings.Default"> setting is applied.</param> + /// <param name="stylesheetResolver">The <see cref="XmlResolver"/> used to resolve any + /// style sheets referenced in XSLT <c>import</c> and <c>include</c> elements. If this is a + /// null reference (Nothing in Visual Basic), external resources are not resolved.</param> public void Load(IXPathNavigable stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheet, settings, stylesheetResolver); @@ -95,19 +118,33 @@ /// <summary> /// Loads and compiles the XSLT style sheet specified by the URI. - /// The XmlResolver resolves any XSLT import or include elements and the + /// The <see cref="XmlResolver"/> resolves any XSLT <c>import</c> or <c>include</c> elements and the /// XSLT settings determine the permissions for the style sheet. - /// </summary> + /// See also <see cref="XslCompiledTransform(string, XsltSettings, XmlResolver)"/>. + /// </summary> + /// <param name="stylesheetUri">The URI of the style sheet.</param> + /// <param name="settings">The <see cref="XsltSettings"/> to apply to the style sheet. + /// If this is a null reference (Nothing in Visual Basic), the <see cref="XsltSettings.Default"> setting is applied.</param> + /// <param name="stylesheetResolver">The <see cref="XmlResolver"/> used to resolve any + /// style sheets referenced in XSLT <c>import</c> and <c>include</c> elements. If this is a + /// null reference (Nothing in Visual Basic), external resources are not resolved.</param> public void Load(string stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheetUri, settings, stylesheetResolver); } /// <summary> - /// Compiles the XSLT style sheet contained in the XmlReader. - /// The XmlResolver resolves any XSLT import or include elements and the + /// Compiles the XSLT style sheet contained in the <see cref="XmlReader"/>. + /// The <see cref="XmlResolver"/> resolves any XSLT <c>import</c> or <c>include</c> elements and the /// XSLT settings determine the permissions for the style sheet. - /// </summary> + /// See also <see cref="XslCompiledTransform(XmlReader, XsltSettings, XmlResolver)"/>. + /// </summary> + /// <param name="stylesheet">The <see cref="XmlReader"/> containing the style sheet.</param> + /// <param name="settings">The <see cref="XsltSettings"/> to apply to the style sheet. + /// If this is a null reference (Nothing in Visual Basic), the <see cref="XsltSettings.Default"> setting is applied.</param> + /// <param name="stylesheetResolver">The <see cref="XmlResolver"/> used to resolve any + /// style sheets referenced in XSLT <c>import</c> and <c>include</c> elements. If this is a + /// null reference (Nothing in Visual Basic), external resources are not resolved.</param> public void Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheet, settings, stylesheetResolver); @@ -162,13 +199,15 @@ /// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlOutput"/>. + /// The <see cref="XsltArgumentList"/> provides additional runtime arguments. /// </summary> - /// <param name="defaulDocument">Default input XML document</param> - /// <param name="args">Parameters</param> - /// <param name="output">Represents the transformation's output</param> - public void Transform(XmlInput defaultDocument, XsltArgumentList args, XmlOutput output) + /// <param name="input">Default input XML document.</param> + /// <param name="arguments">An <see cref="XsltArgumentList"/> containing the namespace-qualified + /// arguments used as input to the transform. This value can be a null reference (Nothing in Visual Basic).</param> + /// <param name="output">Represents the transformation's output.</param> + public void Transform(XmlInput input, XsltArgumentList arguments, XmlOutput output) { - if (defaultDocument == null) throw new ArgumentNullException("defaltDocument"); + if (input == null) throw new ArgumentNullException("defaltDocument"); XmlWriter xmlWriter = output.destination as XmlWriter; bool closeWriter = false; if (xmlWriter == null) @@ -223,7 +262,7 @@ } try { - TransformToWriter(defaultDocument, args, xmlWriter); + TransformToWriter(input, arguments, xmlWriter); } finally { @@ -260,12 +299,13 @@ /// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlReader"/>. /// </summary> - /// <param name="defaulDocument">Default input XML document</param> - /// <param name="args">Parameters</param> - public XmlReader Transform(XmlInput defaultDocument, XsltArgumentList args) + /// <param name="input">Default input XML document</param> + /// <param name="arguments">An <see cref="XsltArgumentList"/> containing the namespace-qualified + /// arguments used as input to the transform. This value can be a null reference (Nothing in Visual Basic).</param> + public XmlReader Transform(XmlInput input, XsltArgumentList arguments) { XslReader r = new XslReader(this.compiledTransform); - r.StartTransform(defaultDocument, AddExsltExtensionObjects(args)); + r.StartTransform(input, AddExsltExtensionObjects(arguments)); return r; } @@ -349,9 +389,9 @@ { object command = this.compiledTransform.GetType().GetField( "command", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this.compiledTransform); - MethodInfo executeMethod = command.GetType().GetMethod("Execute", BindingFlags.Instance | BindingFlags.NonPublic, + MethodInfo executeMethod = command.GetType().GetMethod("Execute", BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(IXPathNavigable), typeof(XmlResolver), typeof(XsltArgumentList), typeof(XmlWriter) }, null); - executeMethod.Invoke(this.compiledTransform, + executeMethod.Invoke(command, new object[] { nav, resolver, AddExsltExtensionObjects(args), xmlWriter }); } |
From: Oleg T. <he...@us...> - 2005-11-20 21:57:05
|
Update of /cvsroot/mvp-xml/Common/v2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20469/v2/test Modified Files: CommonTest.csproj EntryPoint.cs Log Message: Index: CommonTest.csproj =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/test/CommonTest.csproj,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- CommonTest.csproj 19 Nov 2005 22:21:10 -0000 1.6 +++ CommonTest.csproj 20 Nov 2005 21:56:58 -0000 1.7 @@ -179,6 +179,7 @@ </Compile> <Compile Include="XslReaderTests\XslReaderTests.cs" /> <Content Include="changelog.txt" /> + <Content Include="MvpXslTransformTests\resolver-test.xslt" /> <Content Include="MvpXslTransformTests\test.xml" /> <Content Include="MvpXslTransformTests\test1.xslt" /> <Content Include="XslReaderTests\test1.xslt" /> Index: EntryPoint.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/test/EntryPoint.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- EntryPoint.cs 19 Nov 2005 22:21:10 -0000 1.2 +++ EntryPoint.cs 20 Nov 2005 21:56:58 -0000 1.3 @@ -12,7 +12,7 @@ //XslReaderTests.XslReaderTests t = new XslReaderTests.XslReaderTests(); //t.Test5(); MvpXslTransformTests t = new MvpXslTransformTests(); - t.TestStringOutput(); + t.ResolverTestIXPathNavigableInput(); } } } |
From: Oleg T. <he...@us...> - 2005-11-20 21:57:05
|
Update of /cvsroot/mvp-xml/Common/v2/test/MvpXslTransformTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20469/v2/test/MvpXslTransformTests Modified Files: MvpXslTransformTests.cs Added Files: resolver-test.xslt Log Message: --- NEW FILE: resolver-test.xslt --- <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <out> <xsl:copy-of select="document('my://data')" /> </out> </xsl:template> </xsl:stylesheet> Index: MvpXslTransformTests.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/test/MvpXslTransformTests/MvpXslTransformTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- MvpXslTransformTests.cs 19 Nov 2005 22:21:10 -0000 1.1 +++ MvpXslTransformTests.cs 20 Nov 2005 21:56:58 -0000 1.2 @@ -13,7 +13,8 @@ public class MvpXslTransformTests { byte[] standardResult; - MvpXslTransform xslt; + byte[] resolverTestStandardResult; + MvpXslTransform xslt, xslt2; XsltArgumentList args; public MvpXslTransformTests() @@ -25,7 +26,17 @@ { xslt.Transform(r, Arguments, ms); } - standardResult = ms.ToArray(); + standardResult = ms.ToArray(); + XslCompiledTransform xslt2 = new XslCompiledTransform(); + xslt2.Load("../../MvpXslTransformTests/resolver-test.xslt", XsltSettings.TrustedXslt, null); + MemoryStream ms2 = new MemoryStream(); + XmlWriter w = XmlWriter.Create(ms2); + using (XmlReader r2 = XmlReader.Create("../../MvpXslTransformTests/test.xml")) + { + xslt2.Transform(r2, Arguments, w, new MyXmlResolver()); + } + w.Close(); + resolverTestStandardResult = ms2.ToArray(); } private XsltArgumentList Arguments @@ -50,6 +61,16 @@ return xslt; } + private MvpXslTransform GetMvpXslTransform2() + { + if (xslt2 == null) + { + xslt2 = new MvpXslTransform(); + xslt2.Load("../../MvpXslTransformTests/resolver-test.xslt", XsltSettings.TrustedXslt, null); + } + return xslt2; + } + private static void CompareResults(byte[] standard, byte[] test) { Assert.AreEqual(standard.Length, test.Length, string.Format("Lengths are different: {0}, {1}", standard.Length, test.Length)); @@ -249,6 +270,78 @@ fs.Read(bytes, 0, bytes.Length); CompareResults(standardResult, bytes); } - } + } + + + [Test] + public void ResolverTestStringInput() + { + MvpXslTransform xslt = GetMvpXslTransform2(); + XmlInput input = new XmlInput("../../MvpXslTransformTests/test.xml", new MyXmlResolver()); + MemoryStream ms = new MemoryStream(); + xslt.Transform(input, Arguments, new XmlOutput(ms)); + CompareResults(resolverTestStandardResult, ms.ToArray()); + } + + [Test] + public void ResolverTestStreamInput() + { + MvpXslTransform xslt = GetMvpXslTransform2(); + using (FileStream fs = File.OpenRead("../../MvpXslTransformTests/test.xml")) + { + XmlInput input = new XmlInput(fs, new MyXmlResolver()); + MemoryStream ms = new MemoryStream(); + xslt.Transform(input, Arguments, new XmlOutput(ms)); + CompareResults(resolverTestStandardResult, ms.ToArray()); + } + } + + [Test] + public void ResolverTestTextReaderInput() + { + MvpXslTransform xslt = GetMvpXslTransform2(); + XmlInput input = new XmlInput(new StreamReader("../../MvpXslTransformTests/test.xml"), new MyXmlResolver()); + MemoryStream ms = new MemoryStream(); + xslt.Transform(input, Arguments, new XmlOutput(ms)); + CompareResults(resolverTestStandardResult, ms.ToArray()); + } + + [Test] + public void ResolverTestXmlReaderInput() + { + MvpXslTransform xslt = GetMvpXslTransform2(); + XmlInput input = new XmlInput(XmlReader.Create("../../MvpXslTransformTests/test.xml"), new MyXmlResolver()); + MemoryStream ms = new MemoryStream(); + xslt.Transform(input, Arguments, new XmlOutput(ms)); + CompareResults(resolverTestStandardResult, ms.ToArray()); + } + + [Test] + public void ResolverTestIXPathNavigableInput() + { + MvpXslTransform xslt = GetMvpXslTransform2(); + XmlInput input = new XmlInput(new XPathDocument("../../MvpXslTransformTests/test.xml"), new MyXmlResolver()); + MemoryStream ms = new MemoryStream(); + xslt.Transform(input, Arguments, new XmlOutput(ms)); + CompareResults(resolverTestStandardResult, ms.ToArray()); + } + } + + public class MyXmlResolver : XmlUrlResolver + { + public MyXmlResolver() {} + + public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) + { + if (absoluteUri.Scheme == "my") + { + string xml = "<resolver>data</resolver>"; + return XmlReader.Create(new StringReader(xml)); + } + else + { + return base.GetEntity(absoluteUri, role, ofObjectToReturn); + } + } } } |
From: Oleg T. <he...@us...> - 2005-11-19 22:21:32
|
Update of /cvsroot/mvp-xml/Common/v2/src/Xsl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11321/v2/src/Xsl Added Files: MvpXslTransform.cs Log Message: --- NEW FILE: MvpXslTransform.cs --- #region using using System; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; using System.Reflection; using System.CodeDom.Compiler; using Mvp.Xml.Exslt; #endregion namespace Mvp.Xml.Common.Xsl { /// <summary> /// <para>MvpXslTransform class extends capabilities of the <see cref="XslCompiledTransform"/> /// class by adding support for transforming into <see cref="XmlReader"/>, /// vast collection of EXSLT extention functions, multiple outputs and /// transforming of <see cref="IXPathNavigable"/> along with <see cref="XmlResolver"/>. /// Also MvpXslTransform class provides new clean experimental XSL transformation API /// by introducing concepts of <see cref="IXmlTransform"/> interface, <see cref="XmlInput"/> /// and <see cref="XmlOutput"/>.</para> /// </summary> /// <remarks><para>MvpXslTransform class is thread-safe for Transorm() methods. I.e. /// once MvpXslTransform object is loaded, you can safely call its Transform() methods /// in multiple threads simultaneously.</para> /// <para>MvpXslTransform supports EXSLT extension functions from the following namespaces: /// * http://exslt.org/common /// * http://exslt.org/dates-and-times /// * http://exslt.org/math /// * http://exslt.org/random /// * http://exslt.org/regular-expressions /// * http://exslt.org/sets /// * http://exslt.org/strings /// * http://gotdotnet.com/exslt/dates-and-times /// * http://gotdotnet.com/exslt/math /// * http://gotdotnet.com/exslt/regular-expressions /// * http://gotdotnet.com/exslt/sets /// * http://gotdotnet.com/exslt/strings /// * http://gotdotnet.com/exslt/dynamic</para> /// <para>Multioutput (<exsl:document> element) is turned off by default and can /// be turned on using MultiOutput property. Note, that multioutput is not supported /// when transfomation is done to <see cref="XmlWriter"/> or <see cref="XmlReader"/>.</para> /// <para>MvpXslTransform uses XSLT extension objects and reflection and so using /// it requires FullTrust security level.</para> /// </remarks> public class MvpXslTransform : IXmlTransform { private XslCompiledTransform compiledTransform; private object sync = new object(); private ExsltFunctionNamespace supportedFunctions = ExsltFunctionNamespace.All; private bool multiOutput; #region ctors /// <summary> /// Initializes a new instance of the MvpXslTransform class. /// </summary> public MvpXslTransform() { this.compiledTransform = new XslCompiledTransform(); } /// <summary> /// Initializes a new instance of the MvpXslTransform /// class with the specified debug setting. /// </summary> public MvpXslTransform(bool debug) { this.compiledTransform = new XslCompiledTransform(debug); } #endregion #region Load() method overloads /// <summary> Loads the XSLT stylesheet contained in the IXPathNavigable</summary> public void Load(IXPathNavigable ixn) { this.compiledTransform.Load(ixn); } /// <summary> Loads the XSLT stylesheet specified by a URI</summary> public void Load(string stylesheetUri) { this.compiledTransform.Load(stylesheetUri); } /// <summary> Loads the XSLT stylesheet contained in the XmlReader</summary> public void Load(XmlReader reader) { this.compiledTransform.Load(reader); } /// <summary> /// Compiles the XSLT style sheet contained in the IXPathNavigable. /// The XmlResolver resolves any XSLT import or include elements and the /// XSLT settings determine the permissions for the style sheet. /// </summary> public void Load(IXPathNavigable stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheet, settings, stylesheetResolver); } /// <summary> /// Loads and compiles the XSLT style sheet specified by the URI. /// The XmlResolver resolves any XSLT import or include elements and the /// XSLT settings determine the permissions for the style sheet. /// </summary> public void Load(string stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheetUri, settings, stylesheetResolver); } /// <summary> /// Compiles the XSLT style sheet contained in the XmlReader. /// The XmlResolver resolves any XSLT import or include elements and the /// XSLT settings determine the permissions for the style sheet. /// </summary> public void Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) { this.compiledTransform.Load(stylesheet, settings, stylesheetResolver); } #endregion #region public properties /// <summary> /// Bitwise enumeration used to specify which EXSLT functions should be accessible to /// the MvpXslTransform object. The default value is ExsltFunctionNamespace.All /// </summary> public ExsltFunctionNamespace SupportedFunctions { set { if (Enum.IsDefined(typeof(ExsltFunctionNamespace), value)) supportedFunctions = value; } get { return supportedFunctions; } } /// <summary> /// Boolean flag used to specify whether multiple output (via exsl:document) is /// supported. /// Note: This property is ignored (hence multiple output is not supported) when /// transformation is done to XmlReader or XmlWriter (use overloaded method, /// which transforms to MultiXmlTextWriter instead). /// Note: Because of some restrictions and slight overhead this feature is /// disabled by default. If you need multiple output support, set this property to /// true before the Transform() call. /// </summary> public bool MultiOutput { get { return multiOutput; } set { multiOutput = value; } } /// <summary> /// Gets the TempFileCollection that contains the temporary files generated /// on disk after a successful call to the Load method. /// </summary> public TempFileCollection TemporaryFiles { get { return this.compiledTransform.TemporaryFiles; } } #endregion #region IXmlTransform impl /// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlOutput"/>. /// </summary> /// <param name="defaulDocument">Default input XML document</param> /// <param name="args">Parameters</param> /// <param name="output">Represents the transformation's output</param> public void Transform(XmlInput defaultDocument, XsltArgumentList args, XmlOutput output) { if (defaultDocument == null) throw new ArgumentNullException("defaltDocument"); XmlWriter xmlWriter = output.destination as XmlWriter; bool closeWriter = false; if (xmlWriter == null) { closeWriter = true; while (true) { TextWriter txtWriter = output.destination as TextWriter; if (txtWriter != null) { if (multiOutput) { xmlWriter = new MultiXmlTextWriter(txtWriter); } else { xmlWriter = XmlWriter.Create(txtWriter, this.compiledTransform.OutputSettings); } break; } Stream strm = output.destination as Stream; if (strm != null) { if (multiOutput) { xmlWriter = new MultiXmlTextWriter(strm, this.compiledTransform.OutputSettings.Encoding); } else { xmlWriter = XmlWriter.Create(strm, this.compiledTransform.OutputSettings); } break; } String str = output.destination as String; if (str != null) { if (multiOutput) { xmlWriter = new MultiXmlTextWriter(str, this.compiledTransform.OutputSettings.Encoding); } else { XmlWriterSettings outputSettings = this.compiledTransform.OutputSettings.Clone(); outputSettings.CloseOutput = true; // BugBug: We should read doc before creating output file in case they are the same xmlWriter = XmlWriter.Create(str, outputSettings); } break; } throw new Exception("Unexpected XmlOutput"); } } try { TransformToWriter(defaultDocument, args, xmlWriter); } finally { if (closeWriter) { xmlWriter.Close(); } } } /// <summary> /// Gets an <see cref="XmlWriterSettings"/> object that contains the output /// information derived from the xsl:output element of the style sheet. /// </summary> public XmlWriterSettings OutputSettings { get { if (this.compiledTransform != null) { return this.compiledTransform.OutputSettings; } else { return new XmlWriterSettings(); } } } #endregion #region additional Transform() methods /// <summary> /// Transforms given <see cref="XmlInput"/> into <see cref="XmlReader"/>. /// </summary> /// <param name="defaulDocument">Default input XML document</param> /// <param name="args">Parameters</param> public XmlReader Transform(XmlInput defaultDocument, XsltArgumentList args) { XslReader r = new XslReader(this.compiledTransform); r.StartTransform(defaultDocument, AddExsltExtensionObjects(args)); return r; } #endregion #region private stuff private static XmlReaderSettings DefaultReaderSettings; static MvpXslTransform() { DefaultReaderSettings = new XmlReaderSettings(); DefaultReaderSettings.ProhibitDtd = false; } private XmlReaderSettings GetReaderSettings(XmlInput defaultDocument) { if (defaultDocument.resolver is DefaultXmlResolver) { return DefaultReaderSettings; } else { XmlReaderSettings settings = DefaultReaderSettings.Clone(); settings.XmlResolver = defaultDocument.resolver; return settings; } } private void TransformToWriter(XmlInput defaultDocument, XsltArgumentList xsltArgs, XmlWriter xmlWriter) { XsltArgumentList args = AddExsltExtensionObjects(xsltArgs); XmlReader xmlReader = defaultDocument.source as XmlReader; if (xmlReader != null) { this.compiledTransform.Transform(xmlReader, args, xmlWriter, defaultDocument.resolver); return; } IXPathNavigable nav = defaultDocument.source as IXPathNavigable; if (nav != null) { if (defaultDocument.resolver is DefaultXmlResolver) { this.compiledTransform.Transform(nav, args, xmlWriter); } else { TransformIXPathNavigable(nav, args, xmlWriter, defaultDocument.resolver); } return; } string str = defaultDocument.source as string; if (str != null) { using (XmlReader reader = XmlReader.Create(str, GetReaderSettings(defaultDocument))) { this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver); } return; } Stream strm = defaultDocument.source as Stream; if (strm != null) { using (XmlReader reader = XmlReader.Create(strm, GetReaderSettings(defaultDocument))) { this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver); } return; } TextReader txtReader = defaultDocument.source as TextReader; if (txtReader != null) { using (XmlReader reader = XmlReader.Create(txtReader, GetReaderSettings(defaultDocument))) { this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver); } return; } throw new Exception("Unexpected XmlInput"); } private void TransformIXPathNavigable(IXPathNavigable nav, XsltArgumentList args, XmlWriter xmlWriter, XmlResolver resolver) { object command = this.compiledTransform.GetType().GetField( "command", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this.compiledTransform); MethodInfo executeMethod = command.GetType().GetMethod("Execute", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(IXPathNavigable), typeof(XmlResolver), typeof(XsltArgumentList), typeof(XmlWriter) }, null); executeMethod.Invoke(this.compiledTransform, new object[] { nav, resolver, AddExsltExtensionObjects(args), xmlWriter }); } /// <summary> /// Adds the objects that implement the EXSLT extensions to the provided argument /// list. The extension objects added depend on the value of the SupportedFunctions /// property. /// </summary> /// <param name="list">The argument list</param> /// <returns>An XsltArgumentList containing the contents of the list passed in /// and objects that implement the EXSLT. </returns> /// <remarks>If null is passed in then a new XsltArgumentList is constructed. </remarks> private XsltArgumentList AddExsltExtensionObjects(XsltArgumentList list) { if (list == null) { list = new XsltArgumentList(); } lock (sync) { //remove all our extension objects in case the XSLT argument list is being reused list.RemoveExtensionObject(ExsltNamespaces.Math); list.RemoveExtensionObject(ExsltNamespaces.Random); list.RemoveExtensionObject(ExsltNamespaces.DatesAndTimes); list.RemoveExtensionObject(ExsltNamespaces.RegularExpressions); list.RemoveExtensionObject(ExsltNamespaces.Strings); list.RemoveExtensionObject(ExsltNamespaces.Sets); list.RemoveExtensionObject(ExsltNamespaces.GDNDatesAndTimes); list.RemoveExtensionObject(ExsltNamespaces.GDNMath); list.RemoveExtensionObject(ExsltNamespaces.GDNRegularExpressions); list.RemoveExtensionObject(ExsltNamespaces.GDNSets); list.RemoveExtensionObject(ExsltNamespaces.GDNStrings); list.RemoveExtensionObject(ExsltNamespaces.GDNDynamic); //add extension objects as specified by SupportedFunctions if ((this.SupportedFunctions & ExsltFunctionNamespace.Math) > 0) { list.AddExtensionObject(ExsltNamespaces.Math, new ExsltMath()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.Random) > 0) { list.AddExtensionObject(ExsltNamespaces.Random, new ExsltRandom()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.DatesAndTimes) > 0) { list.AddExtensionObject(ExsltNamespaces.DatesAndTimes, new ExsltDatesAndTimes()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.RegularExpressions) > 0) { list.AddExtensionObject(ExsltNamespaces.RegularExpressions, new ExsltRegularExpressions()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.Strings) > 0) { list.AddExtensionObject(ExsltNamespaces.Strings, new ExsltStrings()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.Sets) > 0) { list.AddExtensionObject(ExsltNamespaces.Sets, new ExsltSets()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNDatesAndTimes) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNDatesAndTimes, new GDNDatesAndTimes()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNMath) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNMath, new GDNMath()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNRegularExpressions) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNRegularExpressions, new GDNRegularExpressions()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNSets) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNSets, new GDNSets()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNStrings) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNStrings, new GDNStrings()); } if ((this.SupportedFunctions & ExsltFunctionNamespace.GDNDynamic) > 0) { list.AddExtensionObject(ExsltNamespaces.GDNDynamic, new GDNDynamic()); } } return list; } #endregion } } |
From: Oleg T. <he...@us...> - 2005-11-19 22:21:28
|
Update of /cvsroot/mvp-xml/Common/v2/test/MvpXslTransformTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11321/v2/test/MvpXslTransformTests Added Files: MvpXslTransformTests.cs out.xml test.xml test1.xslt Log Message: --- NEW FILE: test1.xslt --- <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output encoding="utf-8"/> <xsl:param name="prm1" select="'default value'"/> <xsl:template match="/"> <out xmlns="foo" bar="" baz="a&b" xmlns:foo="http://schemas.microsoft.com/xsd/catalog"> <xsl:comment> @#$$ comment</xsl:comment> <xsl:processing-instruction name="pi">ghghghgh gh gh"" ''</xsl:processing-instruction> <prm1> <xsl:value-of select="$prm1" /> </prm1> <xsl:copy-of select="/" /> </out> </xsl:template> </xsl:stylesheet> --- NEW FILE: test.xml --- (This appears to be a binary file; contents omitted.) --- NEW FILE: MvpXslTransformTests.cs --- using System; using NUnit.Framework; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; using System.IO; using System.Text; using Mvp.Xml.Common.Xsl; namespace Mvp.Xml.Tests { [TestFixture] public class MvpXslTransformTests { byte[] standardResult; MvpXslTransform xslt; XsltArgumentList args; public MvpXslTransformTests() { XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load("../../MvpXslTransformTests/test1.xslt"); MemoryStream ms = new MemoryStream(); using (XmlReader r = GetReader(Globals.NorthwindResource)) { xslt.Transform(r, Arguments, ms); } standardResult = ms.ToArray(); } private XsltArgumentList Arguments { get { if (args == null) { args = new XsltArgumentList(); args.AddParam("prm1", "", "value1"); } return args; } } private MvpXslTransform GetMvpXslTransform() { if (xslt == null) { xslt = new MvpXslTransform(); xslt.Load("../../MvpXslTransformTests/test1.xslt"); } return xslt; } private static void CompareResults(byte[] standard, byte[] test) { Assert.AreEqual(standard.Length, test.Length, string.Format("Lengths are different: {0}, {1}", standard.Length, test.Length)); for (int i = 0; i < standard.Length; i++) { Assert.IsTrue(standard[i] == test[i], string.Format("Values aren't equal: {0}, {1}, positoin {2}", standard[i], test[i], i)); } } private static XmlReader GetReader(string xml) { XmlReaderSettings s = new XmlReaderSettings(); s.ProhibitDtd = false; return XmlReader.Create(Globals.GetResource(xml), s); } [Test] public void TestStringInput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput("../../northwind.xml"); MemoryStream ms = new MemoryStream(); xslt.Transform(input, Arguments, new XmlOutput(ms)); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestStreamInput() { MvpXslTransform xslt = GetMvpXslTransform(); using (FileStream fs = File.OpenRead("../../northwind.xml")) { XmlInput input = new XmlInput(fs); MemoryStream ms = new MemoryStream(); xslt.Transform(input, Arguments, new XmlOutput(ms)); CompareResults(standardResult, ms.ToArray()); } } [Test] public void TestTextReaderInput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput(new StreamReader("../../northwind.xml", Encoding.GetEncoding("windows-1252"))); MemoryStream ms = new MemoryStream(); xslt.Transform(input, Arguments, new XmlOutput(ms)); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestXmlReaderInput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput(XmlReader.Create("../../northwind.xml")); MemoryStream ms = new MemoryStream(); xslt.Transform(input, Arguments, new XmlOutput(ms)); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestIXPathNavigableInput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput(new XPathDocument("../../northwind.xml", XmlSpace.Preserve)); MemoryStream ms = new MemoryStream(); xslt.Transform(input, Arguments, new XmlOutput(ms)); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestStringInput2() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput("../../northwind.xml"); MemoryStream ms = new MemoryStream(); XmlReader r = xslt.Transform(input, Arguments); XmlWriter w = XmlWriter.Create(ms); w.WriteNode(r, false); w.Close(); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestStreamInput2() { MvpXslTransform xslt = GetMvpXslTransform(); using (FileStream fs = File.OpenRead("../../northwind.xml")) { XmlInput input = new XmlInput(fs); MemoryStream ms = new MemoryStream(); XmlReader r = xslt.Transform(input, Arguments); XmlWriter w = XmlWriter.Create(ms); w.WriteNode(r, false); w.Close(); CompareResults(standardResult, ms.ToArray()); } } [Test] public void TestTextReaderInput2() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput(new StreamReader("../../northwind.xml", Encoding.GetEncoding("windows-1252"))); MemoryStream ms = new MemoryStream(); XmlReader r = xslt.Transform(input, Arguments); XmlWriter w = XmlWriter.Create(ms); w.WriteNode(r, false); w.Close(); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestXmlReaderInput2() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput(XmlReader.Create("../../northwind.xml")); MemoryStream ms = new MemoryStream(); XmlReader r = xslt.Transform(input, Arguments); XmlWriter w = XmlWriter.Create(ms); w.WriteNode(r, false); w.Close(); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestIXPathNavigableInput2() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput(new XPathDocument("../../northwind.xml", XmlSpace.Preserve)); MemoryStream ms = new MemoryStream(); XmlReader r = xslt.Transform(input, Arguments); XmlWriter w = XmlWriter.Create(ms); w.WriteNode(r, false); w.Close(); CompareResults(standardResult, ms.ToArray()); } [Test] public void TestStringOutput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput("../../northwind.xml"); xslt.Transform(input, Arguments, new XmlOutput("../../MvpXslTransformTests/out.xml")); using (FileStream fs = File.OpenRead("../../MvpXslTransformTests/out.xml")) { byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); CompareResults(standardResult, bytes); } } [Test] public void TestStreamOutput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput("../../northwind.xml"); using (FileStream outStrm = File.OpenWrite("../../MvpXslTransformTests/out.xml")) { xslt.Transform(input, Arguments, new XmlOutput(outStrm)); } using (FileStream fs = File.OpenRead("../../MvpXslTransformTests/out.xml")) { byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); CompareResults(standardResult, bytes); } } [Test] public void TestTextWriterOutput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput("../../northwind.xml"); TextWriter w = new StreamWriter("../../MvpXslTransformTests/out.xml", false, Encoding.UTF8); xslt.Transform(input, Arguments, new XmlOutput(w)); w.Close(); using (FileStream fs = File.OpenRead("../../MvpXslTransformTests/out.xml")) { byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); CompareResults(standardResult, bytes); } } [Test] public void TestXmlWriterOutput() { MvpXslTransform xslt = GetMvpXslTransform(); XmlInput input = new XmlInput("../../northwind.xml"); XmlWriter w = XmlWriter.Create("../../MvpXslTransformTests/out.xml"); xslt.Transform(input, Arguments, new XmlOutput(w)); w.Close(); using (FileStream fs = File.OpenRead("../../MvpXslTransformTests/out.xml")) { byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); CompareResults(standardResult, bytes); } } } } --- NEW FILE: out.xml --- (This appears to be a binary file; contents omitted.) |
From: Oleg T. <he...@us...> - 2005-11-19 22:21:26
|
Update of /cvsroot/mvp-xml/Common/v2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11321/v2/src Modified Files: Common.csproj Log Message: Index: Common.csproj =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/Common.csproj,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Common.csproj 18 Nov 2005 20:51:28 -0000 1.12 +++ Common.csproj 19 Nov 2005 22:21:10 -0000 1.13 @@ -75,6 +75,10 @@ <ErrorReport>prompt</ErrorReport> </PropertyGroup> <ItemGroup> + <Reference Include="Mvp.Xml.Exslt, Version=2.0.2148.42146, Culture=neutral, PublicKeyToken=dd92544dc05f5671, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\EXSLT\v2\src\Exslt\Mvp.Xml.Exslt.dll</HintPath> + </Reference> <Reference Include="System"> <Name>System</Name> </Reference> @@ -146,6 +150,7 @@ <SubType>Code</SubType> </Compile> <Compile Include="Xsl\IXmlTransform.cs" /> + <Compile Include="Xsl\MvpXslTransform.cs" /> <Compile Include="Xsl\XslReader.cs" /> <Content Include="changelog.txt" /> <EmbeddedResource Include="Serialization\PerfCounterInstaller.resx"> |