コード例 #1
0
ファイル: DnaBasePage.cs プロジェクト: rocketeerbkw/DNA
		/// <summary>
		/// Takes the path to an XSLT stylesheet and creates a compiled transformer
		/// </summary>
		/// <param name="xsltFileName">path to the .xsl file</param>
		/// <returns>the XslCompiledTransform object created from the stylesheet</returns>
		public static XslCompiledTransform CreateCompiledTransform(string xsltFileName)
		{
//            bool xsltDebugging = false;
//#if DEBUG
//            // Use xslt debugging?
//            xsltDebugging = true;
//#endif

            XslCompiledTransform transformer = new XslCompiledTransform(false /* xsltDebugging*/);

			// this stuff is necessary to cope with our stylesheets having DTDs
			// Without all this settings and resolver stuff, you can't use the Load method
			// and tell it to allow DTDs
			XmlReaderSettings xset = new XmlReaderSettings();
			xset.ProhibitDtd = false;
			using (XmlReader xread = XmlReader.Create(xsltFileName, xset))
			{
                try
                {
#if DEBUG
                    // Only need to do this on our IIS7 dev environments
                    var transLargeStack = new TransformerLargeStack();
                    transformer = transLargeStack.Load(xsltFileName);
#else
                    transformer.Load(xread, XsltSettings.TrustedXslt, new XmlUrlResolver());
#endif
                }
                catch (Exception e)
                {
                    Type exceptionType = e.GetType();
                    if (exceptionType.Name == "XslLoadException")
                    {
                        int lineNumber = (int)exceptionType.GetMethod("get_LineNumber").Invoke(e, null);
                        int linePosition = (int)exceptionType.GetMethod("get_LinePosition").Invoke(e, null);
                        string fileName = (string)exceptionType.GetMethod("get_SourceUri").Invoke(e, null);
                        throw new XsltException("XSLT Compile error in file " + fileName + " at line " + lineNumber + ", position " + linePosition, e);
                    }
                    else
                    {
                        throw new XsltException("Couldn't load xslt file: " + xsltFileName, e); 
                    }
                }
			}
			return transformer;
		}
コード例 #2
0
ファイル: DnaBasePage.cs プロジェクト: rocketeerbkw/DNA
 /// <summary>
 /// Takes the path to an XSLT stylesheet and creates a compiled transformer
 /// </summary>
 /// <param name="xsltFileName">path to the .xsl file</param>
 /// <returns>the XslCompiledTransform object created from the stylesheet</returns>
 public static XslCompiledTransform CreateCompiledTransformWithLargeStack(string xsltFileName)
 {
     try
     {
         // Only need to do this on our IIS7 dev environments
         var transLargeStack = new TransformerLargeStack();
         return transLargeStack.Load(xsltFileName);
     }
     catch (Exception e)
     {
         Type exceptionType = e.GetType();
         if (exceptionType.Name == "XslLoadException")
         {
             int lineNumber = (int)exceptionType.GetMethod("get_LineNumber").Invoke(e, null);
             int linePosition = (int)exceptionType.GetMethod("get_LinePosition").Invoke(e, null);
             string fileName = (string)exceptionType.GetMethod("get_SourceUri").Invoke(e, null);
             throw new XsltException("XSLT Compile error in file " + fileName + " at line " + lineNumber + ", position " + linePosition, e);
         }
         else
         {
             throw new XsltException("Couldn't load xslt file: " + xsltFileName, e);
         }
     }
 }