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.sort.*; 7 import javax.xml.transform.*; 8 import java.io.*; 9 import java.util.*; 10 11 14 15 public class XSLSort extends StyleElement { 16 17 private SortKeyDefinition sortKeyDefinition; 18 19 public void prepareAttributes() throws TransformerConfigurationException { 20 21 Expression select; 22 Expression order; 23 Expression dataType; 24 Expression caseOrder; 25 Expression lang; 26 27 StandardNames sn = getStandardNames(); 28 AttributeCollection atts = getAttributeList(); 29 30 String selectAtt = null; 31 String orderAtt = null; 32 String dataTypeAtt = null; 33 String caseOrderAtt = null; 34 String langAtt = null; 35 36 for (int a=0; a<atts.getLength(); a++) { 37 int nc = atts.getNameCode(a); 38 int f = nc & 0xfffff; 39 if (f==sn.SELECT) { 40 selectAtt = atts.getValue(a); 41 } else if (f==sn.ORDER) { 42 orderAtt = atts.getValue(a); 43 } else if (f==sn.DATA_TYPE) { 44 dataTypeAtt = atts.getValue(a); 45 } else if (f==sn.CASE_ORDER) { 46 caseOrderAtt = atts.getValue(a); 47 } else if (f==sn.LANG) { 48 langAtt = atts.getValue(a); 49 } else { 50 checkUnknownAttribute(nc); 51 } 52 } 53 54 if (selectAtt==null) { 55 select = new ContextNodeExpression(); 56 } else { 57 select = makeExpression(selectAtt); 58 } 59 60 if (orderAtt == null) { 61 order = new StringValue("ascending"); 62 } else { 63 order = makeAttributeValueTemplate(orderAtt); 64 } 65 66 if (dataTypeAtt == null) { 67 dataType = new StringValue("text"); 68 } else { 69 dataType = makeAttributeValueTemplate(dataTypeAtt); 70 } 71 72 if (caseOrderAtt == null) { 73 caseOrder = new StringValue("#default"); 74 } else { 75 caseOrder = makeAttributeValueTemplate(caseOrderAtt); 76 } 77 78 if (langAtt == null) { 79 lang = new StringValue(Locale.getDefault().getLanguage()); 80 } else { 81 lang = makeAttributeValueTemplate(langAtt); 82 } 83 84 try { 85 sortKeyDefinition = new SortKeyDefinition(); 86 sortKeyDefinition.setSortKey(select); 87 sortKeyDefinition.setOrder(order); 88 sortKeyDefinition.setDataType(dataType); 89 sortKeyDefinition.setCaseOrder(caseOrder); 90 sortKeyDefinition.setLanguage(lang); 91 sortKeyDefinition.setStaticContext(new ExpressionContext(this)); 92 sortKeyDefinition.bindComparer(); 93 } catch (XPathException err) { 94 compileError(err); 95 } 96 } 97 98 public void validate() throws TransformerConfigurationException { 99 NodeInfo parent = (NodeInfo)getParentNode(); 100 if (!((parent instanceof XSLApplyTemplates) || 101 (parent instanceof XSLForEach) || 102 (parent instanceof SAXONGroup) )) { 104 compileError("xsl:sort must be child of xsl:apply-templates or xsl:for-each"); 105 } 106 } 107 108 public void process(Context context) throws TransformerException 109 {} 110 111 public SortKeyDefinition getSortKeyDefinition() { 112 return sortKeyDefinition; 113 } 114 115 } 116 117 | Popular Tags |