001: package net.sf.saxon.style;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.expr.ExpressionTool;
005: import net.sf.saxon.instruct.Executable;
006: import net.sf.saxon.instruct.NextMatch;
007: import net.sf.saxon.om.*;
008: import net.sf.saxon.trans.XPathException;
009: import net.sf.saxon.type.Type;
010: import net.sf.saxon.value.Whitespace;
011:
012: /**
013: * An xsl:next-match element in the stylesheet
014: */
015:
016: public class XSLNextMatch extends StyleElement {
017:
018: /**
019: * Determine whether this node is an instruction.
020: * @return true - it is an instruction
021: */
022:
023: public boolean isInstruction() {
024: return true;
025: }
026:
027: /**
028: * Determine whether this type of element is allowed to contain an xsl:fallback
029: * instruction
030: */
031:
032: public boolean mayContainFallback() {
033: return true;
034: }
035:
036: public void prepareAttributes() throws XPathException {
037:
038: AttributeCollection atts = getAttributeList();
039:
040: for (int a = 0; a < atts.getLength(); a++) {
041: int nc = atts.getNameCode(a);
042: checkUnknownAttribute(nc);
043: }
044: }
045:
046: public void validate() throws XPathException {
047: checkWithinTemplate();
048: AxisIterator kids = iterateAxis(Axis.CHILD);
049: while (true) {
050: NodeInfo child = (NodeInfo) kids.next();
051: if (child == null) {
052: break;
053: }
054: if (child instanceof XSLWithParam
055: || child instanceof XSLFallback) {
056: // OK;
057: } else if (child.getNodeKind() == Type.TEXT) {
058: // with xml:space=preserve, white space nodes may still be there
059: if (!Whitespace.isWhite(child.getStringValueCS())) {
060: compileError(
061: "No character data is allowed within xsl:next-match",
062: "XTSE0010");
063: }
064: } else {
065: compileError("Child element " + child.getDisplayName()
066: + " is not allowed within xsl:next-match",
067: "XTSE0010");
068: }
069: }
070:
071: }
072:
073: public Expression compile(Executable exec) throws XPathException {
074: NextMatch inst = new NextMatch(
075: backwardsCompatibleModeIsEnabled());
076: inst.setActualParameters(getWithParamInstructions(exec, false,
077: inst), getWithParamInstructions(exec, true, inst));
078: ExpressionTool.makeParentReferences(inst);
079: return inst;
080: }
081:
082: }
083:
084: //
085: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
086: // you may not use this file except in compliance with the License. You may obtain a copy of the
087: // License at http://www.mozilla.org/MPL/
088: //
089: // Software distributed under the License is distributed on an "AS IS" basis,
090: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
091: // See the License for the specific language governing rights and limitations under the License.
092: //
093: // The Original Code is: all this file.
094: //
095: // The Initial Developer of the Original Code is Michael H. Kay.
096: //
097: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
098: //
099: // Contributor(s): none.
100: //
|