/// <summary> /// Compile a stylesheet, delivered using an XmlReader. /// </summary> /// <remarks> /// The <c>XmlReader</c> is responsible for parsing the document; this method builds a tree /// representation of the document (in an internal Saxon format) and compiles it. /// If the <c>XmlReader</c> is an <c>XmlTextReader</c>, Saxon will set its <c>Normalization</c> /// property to true, and will wrap it in a (non-validating) <c>XmlValidatingReader</c> to ensure /// that entity references are expanded. /// </remarks> /// <remarks> /// If the <c>XmlReader</c> has a <c>BaseUri</c> property, then that property determines /// the base URI of the stylesheet module, which is used when resolving any <c>xsl:include</c> /// or <c>xsl:import</c> declarations. If the <c>XmlReader</c> has no <c>BaseUri</c> /// property, then the <c>BaseUri</c> property of the <c>Compiler</c> is used instead. /// An <c>ArgumentNullException</c> is thrown if this property has not been supplied. /// </remarks> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(XmlReader reader) { if (reader is XmlTextReader) { ((XmlTextReader)reader).Normalization = true; reader = new XmlValidatingReader(reader); ((XmlValidatingReader)reader).ValidationType = ValidationType.None; } DotNetPullProvider pp = new DotNetPullProvider(reader); JPipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setLocationProvider(pp); pp.setPipelineConfiguration(pipe); // pp = new PullTracer(pp); /* diagnostics */ JPullSource source = new JPullSource(pp); String baseu = reader.BaseURI; if (baseu == null || baseu == String.Empty) { // if no baseURI is supplied by the XmlReader, use the one supplied to this Compiler if (baseUri == null) { throw new ArgumentNullException("BaseUri"); } baseu = baseUri.ToString(); pp.setBaseURI(baseu); } source.setSystemId(baseu); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(source, info); return(new XsltExecutable(pss)); }
/// <summary> /// Compile a stylesheet, retrieving the source using a URI. /// </summary> /// <remarks> /// The document located via the URI is parsed using the <c>System.Xml</c> parser. This /// URI is used as the base URI of the stylesheet: the <c>BaseUri</c> property of the /// <c>Compiler</c> is ignored. /// </remarks> /// <param name="uri">The URI identifying the location where the stylesheet document can be /// found</param> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(Uri uri) { Object obj = XmlResolver.GetEntity(uri, "application/xml", Type.GetType("System.IO.Stream")); if (obj is Stream) { try { XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false; // must expand entity references settings.XmlResolver = XmlResolver; settings.IgnoreWhitespace = false; settings.ValidationType = ValidationType.None; XmlReader parser = XmlReader.Create((Stream)obj, settings, uri.ToString()); //XmlReader parser = new XmlTextReader(uri.ToString(), (Stream)obj); //((XmlTextReader)parser).Normalization = true; //((XmlTextReader)parser).WhitespaceHandling = WhitespaceHandling.All; //((XmlTextReader)parser).XmlResolver = XmlResolver; // Always need a validating parser, because that's the only way to get entity references expanded //parser = new XmlValidatingReader(parser); //((XmlValidatingReader)parser).ValidationType = ValidationType.None; JPullSource source = new JPullSource(new DotNetPullProvider(parser)); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(source, info); return(new XsltExecutable(pss)); } finally { ((Stream)obj).Close(); } } else { throw new ArgumentException("Invalid type of result from XmlResolver.GetEntity: " + obj); } }
/// <summary> /// Compile a stylesheet, retrieving the source using a URI. /// </summary> /// <remarks> /// The document located via the URI is parsed using the <c>System.Xml</c> parser. This /// URI is used as the base URI of the stylesheet: the <c>BaseUri</c> property of the /// <c>Compiler</c> is ignored. /// </remarks> /// <param name="uri">The URI identifying the location where the stylesheet document can be /// found</param> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(Uri uri) { JStreamSource source = new JStreamSource(uri.ToString()); JAugmentedSource aug = JAugmentedSource.makeAugmentedSource(source); aug.setPleaseCloseAfterUse(true); PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(aug, info); return(new XsltExecutable(pss)); }
/// <summary> /// Compile a stylesheet supplied as a Stream. /// </summary> /// <example> /// <code> /// Stream source = new FileStream("input.xsl", FileMode.Open, FileAccess.Read); /// XsltExecutable q = compiler.Compile(source); /// source.Close(); /// </code> /// </example> /// <param name="input">A stream containing the source text of the stylesheet</param> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be loaded as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> /// <remarks> /// <para>If the stylesheet contains any <c>xsl:include</c> or <c>xsl:import</c> declarations, /// then the <c>BaseURI</c> property must be set to allow these to be resolved.</para> /// <para>The stylesheet is contained in the part of the input stream between its current /// position and the end of the stream. It is the caller's responsibility to close the input /// stream after use. If the compilation succeeded, then on exit the stream will be /// exhausted; if compilation failed, the current position of the stream on exit is /// undefined.</para> /// </remarks> public XsltExecutable Compile(Stream input) { JStreamSource ss = new JStreamSource(new DotNetInputStream(input)); if (baseUri != null) { ss.setSystemId(baseUri.ToString()); } PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates(ss, info); return(new XsltExecutable(pss)); }
// internal constructor internal XsltExecutable(PreparedStylesheet pss) { this.pss = pss; }
/// <summary> /// Compile a stylesheet, located at an XdmNode. This may be a document node whose /// child is an <c>xsl:stylesheet</c> or <c>xsl:transform</c> element, or it may be /// the <c>xsl:stylesheet</c> or <c>xsl:transform</c> element itself. /// </summary> /// <returns>An <c>XsltExecutable</c> which represents the compiled stylesheet object. /// The XsltExecutable may be run as many times as required, in the same or a different /// thread. The <c>XsltExecutable</c> is not affected by any changes made to the <c>XsltCompiler</c> /// once it has been compiled.</returns> public XsltExecutable Compile(XdmNode node) { PreparedStylesheet pss = (PreparedStylesheet)factory.newTemplates((JNodeInfo)node.value, info); return(new XsltExecutable(pss)); }