net.sf.saxon.style.XSLGeneralVariable Maven / Gradle / Ivy
package net.sf.saxon.style;
import net.sf.saxon.expr.*;
import net.sf.saxon.instruct.*;
import net.sf.saxon.om.*;
import net.sf.saxon.pattern.NodeKindTest;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;
import net.sf.saxon.type.Type;
import net.sf.saxon.value.Cardinality;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.StringValue;
import net.sf.saxon.value.Whitespace;
/**
* This class defines common behaviour across xsl:variable, xsl:param, and xsl:with-param
*/
public abstract class XSLGeneralVariable extends StyleElement {
protected Expression select = null;
protected SequenceType requiredType = null;
protected String constantText = null;
protected boolean global;
protected SlotManager slotManager = null; // used only for global variable declarations
protected boolean assignable = false;
protected boolean redundant = false;
protected boolean requiredParam = false;
protected boolean implicitlyRequiredParam = false;
protected boolean tunnel = false;
private boolean textonly;
/**
* Determine the type of item returned by this instruction (only relevant if
* it is an instruction).
* @return the item type returned. This is null for a variable: we are not
* interested in the type of the variable, but in what the xsl:variable constributes
* to the result of the sequence constructor it is part of.
*/
protected ItemType getReturnedItemType() {
return null;
}
/**
* Determine whether this type of element is allowed to contain a template-body
* @return true: yes, it may contain a template-body
*/
public boolean mayContainSequenceConstructor() {
return true;
}
protected boolean allowsAsAttribute() {
return true;
}
protected boolean allowsTunnelAttribute() {
return false;
}
protected boolean allowsValue() {
return true;
}
protected boolean allowsRequired() {
return false;
}
/**
* Test whether it is permitted to assign to the variable using the saxon:assign
* extension element.
* @return true if the extra attribute saxon:assignable="yes"
* is present.
*/
public boolean isAssignable() {
return assignable;
}
/**
* Test whether this is a tunnel parameter (tunnel="yes")
* @return true if this is a tunnel parameter
*/
public boolean isTunnelParam() {
return tunnel;
}
/**
* Test whether this is a required parameter (required="yes")
* @return true if this is a required parameter
*/
public boolean isRequiredParam() {
return requiredParam;
}
/**
* Test whether this is a global variable or parameter
* @return true if this is global
*/
public boolean isGlobal() {
return isTopLevel();
// might be called before the "global" field is initialized
}
/**
* Get the display name of the variable.
* @return the lexical QName
*/
public String getVariableDisplayName() {
return getAttributeValue(StandardNames.NAME);
}
/**
* Mark this global variable as redundant. This is done before prepareAttributes is called.
*/
public void setRedundant() {
redundant = true;
}
/**
* Get the QName of the variable
* @return the name as a structured QName, or a dummy name if the variable has no name attribute
* or has an invalid name attribute
*/
public StructuredQName getVariableQName() {
// if an expression has a forwards reference to this variable, getVariableQName() can be
// called before prepareAttributes() is called. We need to allow for this. But we'll
// deal with any errors when we come round to processing this attribute, to avoid
// duplicate error messages
if (getObjectName() == null) {
String nameAttribute = getAttributeValue(StandardNames.NAME);
if (nameAttribute == null) {
return new StructuredQName("saxon", NamespaceConstant.SAXON, "error-variable-name");
}
try {
setObjectName(makeQName(nameAttribute));
} catch (NamespaceException err) {
setObjectName(new StructuredQName("saxon", NamespaceConstant.SAXON, "error-variable-name"));
} catch (XPathException err) {
setObjectName(new StructuredQName("saxon", NamespaceConstant.SAXON, "error-variable-name"));
}
}
return getObjectName();
}
public void prepareAttributes() throws XPathException {
getVariableQName();
AttributeCollection atts = getAttributeList();
String selectAtt = null;
String assignAtt = null;
String nameAtt = null;
String asAtt = null;
String requiredAtt = null;
String tunnelAtt = null;
for (int a=0; a 0) {
gvar.setContainsLocals(slotManager);
}
exec.registerGlobalVariable(gvar);
setReferenceCount(gvar);
if (exp2 != select) {
gvar.setSelectExpression(exp2);
}
}
}
protected void setReferenceCount(GeneralVariable var) {
// overridden in subclass
}
/**
* Get the type of construct. This will be a constant in
* class {@link net.sf.saxon.trace.Location}. This method is part of the
* {@link net.sf.saxon.trace.InstructionInfo} interface
*/
public int getConstructType() {
return StandardNames.XSL_VARIABLE;
}
}
//
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy of the
// License at http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
// See the License for the specific language governing rights and limitations under the License.
//
// The Original Code is: all this file.
//
// The Initial Developer of the Original Code is Michael H. Kay.
//
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
//
// Contributor(s): none.
//
© 2015 - 2025 Weber Informatics LLC | Privacy Policy