1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.Context; 4 import com.icl.saxon.om.Name; 5 import com.icl.saxon.expr.Expression; 6 import com.icl.saxon.output.Outputter; 7 import javax.xml.transform.TransformerException ; 8 import javax.xml.transform.TransformerConfigurationException ; 9 10 12 15 16 public class XSLProcessingInstruction extends XSLStringConstructor { 17 18 Expression name; 19 20 public void prepareAttributes() throws TransformerConfigurationException { 21 22 String nameAtt = null; 23 24 StandardNames sn = getStandardNames(); 25 AttributeCollection atts = getAttributeList(); 26 27 for (int a=0; a<atts.getLength(); a++) { 28 int nc = atts.getNameCode(a); 29 int f = nc & 0xfffff; 30 if (f==sn.NAME) { 31 nameAtt = atts.getValue(a); 32 } else { 33 checkUnknownAttribute(nc); 34 } 35 } 36 if (nameAtt==null) { 37 reportAbsence("name"); 38 } else { 39 name = makeAttributeValueTemplate(nameAtt); 40 } 41 } 42 43 public void validate() throws TransformerConfigurationException { 44 checkWithinTemplate(); 45 optimize(); 46 } 47 48 49 public void process(Context context) throws TransformerException 50 { 51 String expandedName = name.evaluateAsString(context); 52 53 if (!(Name.isNCName(expandedName)) || expandedName.equalsIgnoreCase("xml")) { 54 context.getController().reportRecoverableError( 55 "Processing instruction name is invalid: " + expandedName, this); 56 return; 57 } 58 59 String data = expandChildren(context); 60 61 int hh = data.indexOf("?>"); 62 if (hh >= 0) { 63 context.getController().reportRecoverableError( 64 "Invalid characters (?>) in processing instruction", this); 65 data = data.substring(0, hh+1) + " " + data.substring(hh+1); 66 } 67 68 context.getOutputter().writePI(expandedName, data); 69 } 70 71 72 } 73 74 | Popular Tags |