1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.*; 4 import com.icl.saxon.om.Name; 5 import com.icl.saxon.om.NamePool; 6 import com.icl.saxon.om.NamespaceException; 7 import com.icl.saxon.expr.*; 8 import com.icl.saxon.output.*; 9 import javax.xml.transform.*; 10 11 12 15 16 public class XSLElement extends StyleElement { 17 18 private Expression elementName; 19 private Expression namespace = null; 20 private String use; 21 private boolean declared = false; 23 27 28 public boolean isInstruction() { 29 return true; 30 } 31 32 36 37 public boolean mayContainTemplateBody() { 38 return true; 39 } 40 41 public void prepareAttributes() throws TransformerConfigurationException { 42 43 StandardNames sn = getStandardNames(); 44 AttributeCollection atts = getAttributeList(); 45 46 String nameAtt = null; 47 String namespaceAtt = null; 48 49 for (int a=0; a<atts.getLength(); a++) { 50 int nc = atts.getNameCode(a); 51 int f = nc & 0xfffff; 52 if (f==sn.NAME) { 53 nameAtt = atts.getValue(a); 54 } else if (f==sn.NAMESPACE) { 55 namespaceAtt = atts.getValue(a); 56 } else if (f==sn.USE_ATTRIBUTE_SETS) { 57 use = atts.getValue(a); 58 } else { 59 checkUnknownAttribute(nc); 60 } 61 } 62 63 if (nameAtt==null) { 64 reportAbsence("name"); 65 } else { 66 elementName = makeAttributeValueTemplate(nameAtt); 67 if (elementName instanceof StringValue) { 68 if (!Name.isQName(((StringValue)elementName).asString())) { 69 compileError("Element name is not a valid QName"); 70 } 71 } 72 } 73 74 if (namespaceAtt!=null) { 75 namespace = makeAttributeValueTemplate(namespaceAtt); 76 } 77 78 } 79 80 public void validate() throws TransformerConfigurationException { 81 checkWithinTemplate(); 82 if (use!=null) { 83 findAttributeSets(use); } 85 } 86 87 public void process(Context context) throws TransformerException 88 { 89 Controller controller = context.getController(); 90 NamePool pool = controller.getNamePool(); 91 92 94 String expandedName = elementName.evaluateAsString(context); 95 96 if (!Name.isQName(expandedName)) { 97 controller.reportRecoverableError( 98 "Invalid element name: " + expandedName, this); 99 context.getOutputter().writeStartTag(-1); 102 processChildren(context); 103 return; 104 } 105 106 String prefix = Name.getPrefix(expandedName); 107 short uriCode; 108 109 if (namespace==null) { 110 111 try { 114 uriCode = getURICodeForPrefix(prefix); } catch (NamespaceException err) { 116 throw styleError(err.getMessage()); 118 } 119 120 } else { 121 122 String uri = namespace.evaluateAsString(context); 123 if (uri.equals("")) { 124 prefix = ""; 127 } 128 uriCode = pool.allocateCodeForURI(uri); 129 } 130 131 String localName = Name.getLocalName(expandedName); 132 int nameCode = pool.allocate(prefix, uriCode, localName); 133 134 Outputter out = context.getOutputter(); 135 out.writeStartTag(nameCode); 136 out.writeNamespaceDeclaration(pool.allocateNamespaceCode(nameCode)); 137 138 processAttributeSets(context); 140 141 processChildren(context); 143 144 out.writeEndTag(nameCode); 146 } 147 148 149 } 150 151 | Popular Tags |