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.NamespaceException; 6 import com.icl.saxon.pattern.Pattern; 7 import com.icl.saxon.expr.Expression; 8 import com.icl.saxon.expr.XPathException; 9 import javax.xml.transform.*; 10 11 import java.util.*; 12 13 16 17 public class XSLKey extends StyleElement { 18 19 private int fingerprint; private Pattern match; 21 private Expression use; 22 23 public void prepareAttributes() throws TransformerConfigurationException { 24 25 String nameAtt = null; 26 String matchAtt = null; 27 String useAtt = null; 28 29 StandardNames sn = getStandardNames(); 30 AttributeCollection atts = getAttributeList(); 31 32 for (int a=0; a<atts.getLength(); a++) { 33 int nc = atts.getNameCode(a); 34 int f = nc & 0xfffff; 35 if (f==sn.NAME) { 36 nameAtt = atts.getValue(a); 37 } else if (f==sn.USE) { 38 useAtt = atts.getValue(a); 39 } else if (f==sn.MATCH) { 40 matchAtt = atts.getValue(a); 41 } else { 42 checkUnknownAttribute(nc); 43 } 44 } 45 46 if (nameAtt==null) { 47 reportAbsence("name"); 48 return; 49 } 50 if (!Name.isQName(nameAtt)) { 51 compileError("Name of key must be a valid QName"); 52 return; 53 } 54 try { 55 fingerprint = makeNameCode(nameAtt, false) & 0xfffff; 56 } catch (NamespaceException err) { 57 compileError(err.getMessage()); 58 } 59 60 if (matchAtt==null) { 61 reportAbsence("match"); 62 } else { 63 match = makePattern(matchAtt); 64 } 65 66 if (useAtt==null) { 67 reportAbsence("use"); 68 } else { 69 use = makeExpression(useAtt); 70 } 71 } 72 73 public void validate() throws TransformerConfigurationException { 74 checkTopLevel(); 75 checkEmpty(); 76 } 77 78 public void preprocess() throws TransformerConfigurationException 79 { 80 KeyManager km = getPrincipalStyleSheet().getKeyManager(); 81 km.setKeyDefinition(new KeyDefinition(fingerprint, match, use)); 82 } 83 84 public void process(Context context) throws TransformerException 85 {} 86 87 90 91 public Binding bindVariable(int fingerprint) throws XPathException { 92 throw new XPathException("The expressions in xsl:key may not contain references to variables"); 93 } 94 95 } 96 | Popular Tags |