| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Expression; |
| 11 |
import net.sf.saxon.expr.Literal; |
| 12 |
import net.sf.saxon.expr.sort.SortExpression; |
| 13 |
import net.sf.saxon.expr.sort.SortKeyDefinitionList; |
| 14 |
import net.sf.saxon.om.AttributeCollection; |
| 15 |
import net.sf.saxon.om.AxisInfo; |
| 16 |
import net.sf.saxon.om.NodeInfo; |
| 17 |
import net.sf.saxon.trans.XPathException; |
| 18 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 19 |
import net.sf.saxon.type.Type; |
| 20 |
import net.sf.saxon.value.Whitespace; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class XSLPerformSort extends StyleElement { |
| 28 |
|
| 29 |
Expression select = null; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public boolean isInstruction() { |
| 38 |
return true; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public boolean mayContainSequenceConstructor() { |
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
protected boolean isPermittedChild(StyleElement child) { |
| 56 |
return (child instanceof XSLSort); |
| 57 |
} |
| 58 |
|
| 59 |
public void prepareAttributes() throws XPathException { |
| 60 |
|
| 61 |
AttributeCollection atts = getAttributeList(); |
| 62 |
|
| 63 |
String selectAtt = null; |
| 64 |
|
| 65 |
for (int a = 0; a < atts.getLength(); a++) { |
| 66 |
String f = atts.getQName(a); |
| 67 |
if (f.equals("select")) { |
| 68 |
selectAtt = atts.getValue(a); |
| 69 |
select = makeExpression(selectAtt, a); |
| 70 |
} else { |
| 71 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 78 |
checkSortComesFirst(true); |
| 79 |
|
| 80 |
if (select != null) { |
| 81 |
|
| 82 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 83 |
while (true) { |
| 84 |
NodeInfo child = (NodeInfo) kids.next(); |
| 85 |
if (child == null) { |
| 86 |
break; |
| 87 |
} |
| 88 |
if (child instanceof XSLSort || child instanceof XSLFallback) { |
| 89 |
|
| 90 |
} else if (child.getNodeKind() == Type.TEXT && !Whitespace.isWhite(child.getStringValueCS())) { |
| 91 |
|
| 92 |
compileError("Within xsl:perform-sort, significant text must not appear if there is a select attribute", |
| 93 |
"XTSE1040"); |
| 94 |
} else { |
| 95 |
((StyleElement) child).compileError( |
| 96 |
"Within xsl:perform-sort, child instructions are not allowed if there is a select attribute", |
| 97 |
"XTSE1040"); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
select = typeCheck("select", select); |
| 102 |
} |
| 103 |
|
| 104 |
public Expression compile(Compilation compilation, ComponentDeclaration decl) throws XPathException { |
| 105 |
SortKeyDefinitionList sortKeys = makeSortKeys(compilation, decl); |
| 106 |
if (select != null) { |
| 107 |
return new SortExpression(select, sortKeys); |
| 108 |
} else { |
| 109 |
Expression body = compileSequenceConstructor(compilation, decl, true); |
| 110 |
if (body == null) { |
| 111 |
body = Literal.makeEmptySequence(); |
| 112 |
} |
| 113 |
try { |
| 114 |
return new SortExpression(body.simplify(), sortKeys); |
| 115 |
} catch (XPathException e) { |
| 116 |
compileError(e); |
| 117 |
return null; |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
} |