001: package net.sf.saxon.style;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.instruct.Executable;
005: import net.sf.saxon.om.AttributeCollection;
006: import net.sf.saxon.trans.XPathException;
007: import net.sf.saxon.type.ItemType;
008:
009: /**
010: * Handler for xsl:when elements in stylesheet. <br>
011: * The xsl:while element has a mandatory attribute test, a boolean expression.
012: */
013:
014: public class XSLWhen extends StyleElement {
015:
016: private Expression test;
017:
018: public Expression getCondition() {
019: return test;
020: }
021:
022: /**
023: * Determine the type of item returned by this instruction (only relevant if
024: * it is an instruction).
025: * @return the item type returned
026: */
027:
028: protected ItemType getReturnedItemType() {
029: return getCommonChildItemType();
030: }
031:
032: public void prepareAttributes() throws XPathException {
033: String testAtt = null;
034:
035: AttributeCollection atts = getAttributeList();
036:
037: for (int a = 0; a < atts.getLength(); a++) {
038: int nc = atts.getNameCode(a);
039: String f = getNamePool().getClarkName(nc);
040: if (f == StandardNames.TEST) {
041: testAtt = atts.getValue(a);
042: } else {
043: checkUnknownAttribute(nc);
044: }
045: }
046:
047: if (testAtt == null) {
048: reportAbsence("test");
049: } else {
050: test = makeExpression(testAtt);
051: }
052: }
053:
054: /**
055: * Determine whether this type of element is allowed to contain a template-body
056: * @return true: yes, it may contain a template-body
057: */
058:
059: public boolean mayContainSequenceConstructor() {
060: return true;
061: }
062:
063: public void validate() throws XPathException {
064: if (!(getParent() instanceof XSLChoose)) {
065: compileError(
066: "xsl:when must be immediately within xsl:choose",
067: "XTSE0010");
068: }
069: test = typeCheck("test", test);
070: }
071:
072: /**
073: * Mark tail-recursive calls on stylesheet functions. For most instructions, this does nothing.
074: */
075:
076: public void markTailCalls() {
077: StyleElement last = getLastChildInstruction();
078: if (last != null) {
079: last.markTailCalls();
080: }
081: }
082:
083: public Expression compile(Executable exec) throws XPathException {
084: return null;
085: // compilation is handled from the xsl:choose element
086: }
087:
088: }
089:
090: //
091: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
092: // you may not use this file except in compliance with the License. You may obtain a copy of the
093: // License at http://www.mozilla.org/MPL/
094: //
095: // Software distributed under the License is distributed on an "AS IS" basis,
096: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
097: // See the License for the specific language governing rights and limitations under the License.
098: //
099: // The Original Code is: all this file.
100: //
101: // The Initial Developer of the Original Code is Michael H. Kay.
102: //
103: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
104: //
105: // Contributor(s): none.
106: //
|