package client.net.sf.saxon.ce.style;
import client.net.sf.saxon.ce.expr.Expression;
import client.net.sf.saxon.ce.expr.instruct.CopyOf;
import client.net.sf.saxon.ce.expr.instruct.Executable;
import client.net.sf.saxon.ce.lib.Validation;
import client.net.sf.saxon.ce.om.AttributeCollection;
import client.net.sf.saxon.ce.om.StandardNames;
import client.net.sf.saxon.ce.trans.XPathException;
import client.net.sf.saxon.ce.value.Whitespace;
/**
* An xsl:copy-of element in the stylesheet. <br>
*/
public final class XSLCopyOf extends StyleElement {
private Expression select;
private boolean copyNamespaces;
/**
* Determine whether this node is an instruction.
* @return true - it is an instruction
*/
public boolean isInstruction() {
return true;
}
public void prepareAttributes() throws XPathException {
AttributeCollection atts = getAttributeList();
String selectAtt = null;
String copyNamespacesAtt = null;
String validationAtt = null;
String typeAtt = null;
for (int a=0; a<atts.getLength(); a++) {
int nc = atts.getNameCode(a);
String f = getNamePool().getClarkName(nc);
if (f.equals(StandardNames.SELECT)) {
selectAtt = atts.getValue(a);
} else if (f.equals(StandardNames.COPY_NAMESPACES)) {
copyNamespacesAtt = Whitespace.trim(atts.getValue(a));
} else if (f.equals(StandardNames.VALIDATION)) {
validationAtt = Whitespace.trim(atts.getValue(a));
} else if (f.equals(StandardNames.TYPE)) {
typeAtt = Whitespace.trim(atts.getValue(a));
} else {
checkUnknownAttribute(nc);
}
}
if (selectAtt!=null) {
select = makeExpression(selectAtt);
} else {
reportAbsence("select");
}
if (copyNamespacesAtt == null) {
copyNamespaces = true;
} else {
if (copyNamespacesAtt.equals("yes")) {
copyNamespaces = true;
} else if (copyNamespacesAtt.equals("no")) {
copyNamespaces = false;
} else {
compileError("Value of copy-namespaces must be 'yes' or 'no'", "XTSE0020");
}
}
if (validationAtt != null && Validation.getCode(validationAtt) != Validation.STRIP) {
compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660");
}
if (typeAtt!=null) {
compileError("The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660");
}
}
public void validate(Declaration decl) throws XPathException {
checkEmpty();
select = typeCheck(select);
}
public Expression compile(Executable exec, Declaration decl) {
CopyOf inst = new CopyOf(select, copyNamespaces);
inst.setStaticBaseUri(getBaseURI());
return inst;
}
}
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.