1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.*; 4 import com.icl.saxon.om.*; 5 import com.icl.saxon.expr.*; 6 import com.icl.saxon.output.Outputter; 7 import javax.xml.transform.*; 8 9 10 16 17 public class XSLCopyOf extends StyleElement { 18 19 Expression select; 20 21 25 26 public boolean isInstruction() { 27 return true; 28 } 29 30 31 public void prepareAttributes() throws TransformerConfigurationException { 32 33 StandardNames sn = getStandardNames(); 34 AttributeCollection atts = getAttributeList(); 35 String selectAtt = null; 36 37 for (int a=0; a<atts.getLength(); a++) { 38 int nc = atts.getNameCode(a); 39 int f = nc & 0xfffff; 40 if (f==sn.SELECT) { 41 selectAtt = atts.getValue(a); 42 } else { 43 checkUnknownAttribute(nc); 44 } 45 } 46 47 if (selectAtt!=null) { 48 select = makeExpression(selectAtt); 49 } else { 50 reportAbsence("select"); 51 } 52 } 53 54 public void validate() throws TransformerConfigurationException { 55 checkWithinTemplate(); 56 checkEmpty(); 57 } 58 59 public void process(Context context) throws TransformerException 60 { 61 62 if (select instanceof NodeSetExpression) { 63 copyNodeSet(select, context); 64 } else { 65 Value value = select.evaluate(context); 66 if (value instanceof FragmentValue) { 67 ((FragmentValue)value).copy(context.getOutputter()); 68 69 } else if (value instanceof TextFragmentValue) { 70 ((TextFragmentValue)value).copy(context.getOutputter()); 71 72 } else if (value instanceof NodeSetValue) { 73 copyNodeSet((NodeSetValue)value, context); 74 75 } else { 76 context.getOutputter().writeContent(value.asString()); 77 } 78 } 79 } 80 81 private void copyNodeSet(Expression nodeSet, Context c) throws TransformerException { 82 Outputter out = c.getOutputter(); 83 NodeEnumeration enum = nodeSet.enumerate(c, true); 84 while (enum.hasMoreElements()) { 85 NodeInfo node = enum.nextElement(); 86 node.copy(out); 87 } 88 } 89 90 } 91 92 | Popular Tags |