1 package net.sf.saxon.functions; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.expr.StaticContext; 4 import net.sf.saxon.expr.XPathContext; 5 import net.sf.saxon.om.DocumentInfo; 6 import net.sf.saxon.om.Item; 7 import net.sf.saxon.trans.XPathException; 8 import net.sf.saxon.value.StringValue; 9 10 14 15 16 public class UnparsedEntity extends SystemFunction implements XSLTFunction { 17 18 public static int URI = 0; 19 public static int PUBLIC_ID = 1; 20 21 24 25 public Expression simplify(StaticContext env) throws XPathException { 26 UnparsedEntity f = (UnparsedEntity)super.simplify(env); 27 f.addContextDocumentArgument(1, (operation==URI ? "unparsed-entity-uri_9999_": "unparsed-entity-public-id_9999_")); 28 return f; 29 } 30 31 34 35 public Expression preEvaluate(StaticContext env) { 36 return this; 37 } 38 39 42 43 public Item evaluateItem(XPathContext context) throws XPathException { 44 String arg0 = argument[0].evaluateItem(context).getStringValue(); 45 Item doc = argument[1].evaluateItem(context); 46 if (!(doc instanceof DocumentInfo)) { 47 String code = (operation==URI ? "XTDE1370" : "XTDE1380"); 48 dynamicError("In function " + getDisplayName(context.getController().getNamePool()) + 49 ", the context node must be in a tree whose root is a document node", code, context); 50 } 51 String [] ids = ((DocumentInfo)doc).getUnparsedEntity(arg0); 52 if (ids==null) return StringValue.EMPTY_STRING; 53 return new StringValue(ids[operation]); 54 } 55 56 } 57 58 59 60 61 | Popular Tags |