| 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.StringLiteral; |
| 12 |
import net.sf.saxon.expr.instruct.NamespaceConstructor; |
| 13 |
import net.sf.saxon.om.AxisInfo; |
| 14 |
import net.sf.saxon.om.NodeInfo; |
| 15 |
import net.sf.saxon.trans.XPathException; |
| 16 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 17 |
import net.sf.saxon.type.Type; |
| 18 |
import net.sf.saxon.value.StringValue; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class XSLNamespace extends XSLLeafNodeConstructor { |
| 25 |
|
| 26 |
Expression name; |
| 27 |
|
| 28 |
public void prepareAttributes() throws XPathException { |
| 29 |
name = prepareAttributesNameAndSelect(); |
| 30 |
} |
| 31 |
|
| 32 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 33 |
name = typeCheck("name", name); |
| 34 |
select = typeCheck("select", select); |
| 35 |
int countChildren = 0; |
| 36 |
NodeInfo firstChild = null; |
| 37 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 38 |
while (true) { |
| 39 |
NodeInfo child = kids.next(); |
| 40 |
if (child == null) { |
| 41 |
break; |
| 42 |
} |
| 43 |
if (child instanceof XSLFallback) { |
| 44 |
continue; |
| 45 |
} |
| 46 |
if (select != null) { |
| 47 |
String errorCode = getErrorCodeForSelectPlusContent(); |
| 48 |
compileError("An " + getDisplayName() + " element with a select attribute must be empty", errorCode); |
| 49 |
} |
| 50 |
countChildren++; |
| 51 |
if (firstChild == null) { |
| 52 |
firstChild = child; |
| 53 |
} else { |
| 54 |
break; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
if (select == null) { |
| 59 |
if (countChildren == 0) { |
| 60 |
|
| 61 |
select = new StringLiteral(StringValue.EMPTY_STRING); |
| 62 |
select.setRetainedStaticContext(makeRetainedStaticContext()); |
| 63 |
} else if (countChildren == 1) { |
| 64 |
|
| 65 |
if (firstChild.getNodeKind() == Type.TEXT) { |
| 66 |
|
| 67 |
select = new StringLiteral(firstChild.getStringValueCS()); |
| 68 |
select.setRetainedStaticContext(makeRetainedStaticContext()); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
protected String getErrorCodeForSelectPlusContent() { |
| 81 |
return "XTSE0910"; |
| 82 |
} |
| 83 |
|
| 84 |
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { |
| 85 |
NamespaceConstructor inst = new NamespaceConstructor(name); |
| 86 |
compileContent(exec, decl, inst, new StringLiteral(StringValue.SINGLE_SPACE)); |
| 87 |
return inst; |
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
|