1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.*; 4 import com.icl.saxon.expr.*; 5 import com.icl.saxon.pattern.*; 6 import com.icl.saxon.om.*; 7 import javax.xml.transform.*; 8 import java.util.*; 9 10 13 14 public class XSLPreserveSpace extends StyleElement { 15 16 private String elements; 17 18 public void prepareAttributes() throws TransformerConfigurationException { 19 20 StandardNames sn = getStandardNames(); 21 AttributeCollection atts = getAttributeList(); 22 23 for (int a=0; a<atts.getLength(); a++) { 24 int nc = atts.getNameCode(a); 25 int f = nc & 0xfffff; 26 if (f==sn.ELEMENTS) { 27 elements = atts.getValue(a); 28 } else { 29 checkUnknownAttribute(nc); 30 } 31 } 32 if (elements==null) { 33 reportAbsence("elements"); 34 elements="*"; } 36 } 37 38 public void validate() throws TransformerConfigurationException { 39 checkTopLevel(); 40 } 41 42 public void preprocess() throws TransformerConfigurationException 43 { 44 Boolean preserve = new Boolean (getFingerprint()==getStandardNames().XSL_PRESERVE_SPACE); 45 Mode stripperRules = getPrincipalStyleSheet().getStripperRules(); 46 47 49 StringTokenizer st = new StringTokenizer(elements); 50 while (st.hasMoreTokens()) { 51 String s = st.nextToken(); 52 try { 53 if (s.equals("*")) { 54 stripperRules.addRule( 55 AnyNodeTest.getInstance(), 56 preserve, 57 getPrecedence(), 58 -0.5); 59 60 } else if (s.endsWith(":*")) { 61 String prefix = s.substring(0, s.length()-2); 62 stripperRules.addRule( 63 new NamespaceTest( 64 getNamePool(), 65 NodeInfo.ELEMENT, 66 getURICodeForPrefix(prefix)), 67 preserve, 68 getPrecedence(), 69 -0.25); 70 } else { 71 if (!Name.isQName(s)) { 72 compileError("Element name " + s + " is not a valid QName"); 73 } 74 stripperRules.addRule( 75 new NameTest( 76 NodeInfo.ELEMENT, 77 makeNameCode(s, false)), 78 preserve, 79 getPrecedence(), 80 0); 81 } 82 } catch (NamespaceException err) { 83 compileError(err.getMessage()); 84 } 85 } 86 } 87 88 public void process(Context c) {} 89 90 } 91 92 | Popular Tags |