+2004-05-20 Atsushi Enomoto <atsushi@ximian.com>
+
+ * Compiler.cs :
+ - CompilePattern() now throws XsltCompileException for invalid
+ pattern, and add error location support.
+ - In Compiler.TryGetFunction(), compare namespace URI, not prefix.
+ Now it returns MSXslNodeSet instance (for msxsl:node-set).
+ * Debug.cs : don't throw System.Exception.
+ * XslFunctions.cs : Added MSXslNodeSet class.
+ * XslTemplate.cs : reflected CompilePattern() change.
+ * XslTransformProcessor.cs : don't throw System.Exception.
+ * XsltCompiledContext.cs : don't throw System.Exception.
+
2004-05-12 Atsushi Enomoto <atsushi@ximian.com>
* XmlOutputter.cs,
#endregion
#region Compile
- public Pattern CompilePattern (string pattern)
+ public Pattern CompilePattern (string pattern, XPathNavigator loc)
{
if (pattern == null || pattern == "") return null;
Pattern p = Pattern.Compile (pattern, this);
-
+ if (p == null)
+ throw new XsltCompileException (String.Format ("Invalid pattern '{0}'.", pattern), null, loc);
exprStore.AddPattern (p, this);
return p;
Expression IStaticXsltContext.TryGetFunction (QName name, FunctionArguments args)
{
- if (name.Namespace != null && name.Namespace != "")
- return null;
+ string ns = GetNsm ().LookupNamespace (name.Namespace);
+ if (ns == XslStylesheet.MSXsltNamespace && name.Name == "node-set")
+ return new MSXslNodeSet (args);
+ if (ns != "")
+ return null;
+
switch (name.Name) {
case "current": return new XsltCurrent (args);
case "unparsed-entity-uri": return new XsltUnparsedEntityUri (args);
internal static void Assert (bool condition, string message)
{
if (!condition)
- throw new Exception (message);
+ throw new XsltException (message, null);
}
[System.Diagnostics.Conditional("_DEBUG")]
return ent.BaseURI;
}
}
+
+ class MSXslNodeSet : XPathFunction
+ {
+ Expression arg0;
+
+ public MSXslNodeSet (FunctionArguments args) : base (args)
+ {
+ if (args == null || args.Tail != null)
+ throw new XPathException ("element-available takes 1 arg");
+
+ arg0 = args.Arg;
+ }
+\r
+ public override XPathResultType ReturnType {\r
+ get {\r
+ return XPathResultType.NodeSet;\r
+ }\r
+ }\r
+
+ public override object Evaluate (BaseIterator iter)\r
+ {\r
+ XsltCompiledContext ctx = iter.NamespaceManager as XsltCompiledContext;\r
+ XPathNavigator loc = iter.Current != null ? iter.Current.Clone () : null;\r
+ XPathNavigator nav = arg0.EvaluateAs (iter, XPathResultType.Navigator) as XPathNavigator;\r
+ if (nav == null) {\r
+ if (loc != null)\r
+ return new XsltException ("Cannot convert the XPath argument to a result tree fragment.", null, loc);\r
+ else\r
+ return new XsltException ("Cannot convert the XPath argument to a result tree fragment.", null);\r
+ }\r
+ ArrayList al = new ArrayList ();\r
+ al.Add (nav);\r
+ return new ListIterator (al, ctx, false);\r
+ }
+ }
}
this.mode = QName.Empty;
} else {
this.name = c.ParseQNameAttribute ("name");
- this.match = c.CompilePattern (c.GetAttribute ("match"));
+ this.match = c.CompilePattern (c.GetAttribute ("match"), c.Input);
this.mode = c.ParseQNameAttribute ("mode");
string pri = c.GetAttribute ("priority");
{
#if DEBUG
if (avtSBlock)
- throw new Exception ("String Builder was locked");
+ throw new XsltException ("String Builder was locked", null);
avtSBlock = true;
#endif
{
#if DEBUG
if (!avtSBlock)
- throw new Exception ("you never locked the string builder");
+ throw new XsltException ("you never locked the string builder", null);
avtSBlock = false;
#endif
public override string LookupNamespace (string prefix)
{
- throw new Exception ("we should never get here");
+ throw new InvalidOperationException ("we should never get here");
}
internal override IXsltContextFunction ResolveFunction (XmlQualifiedName name, XPathResultType [] argTypes)
public override IXsltContextVariable ResolveVariable (string prefix, string name)
{
- throw new Exception ("shouldn't get here");
+ throw new InvalidOperationException ("shouldn't get here");
}
public override IXsltContextFunction ResolveFunction (string prefix, string name, XPathResultType [] ArgTypes)
{
- throw new Exception ("shouldn't get here");
+ throw new InvalidOperationException ("XsltCompiledContext exception: shouldn't get here.");
}
internal override System.Xml.Xsl.IXsltContextVariable ResolveVariable(QName q)