Debian Codegraph @

net/sf/saxon/trans/rules/DeepSkipRuleSet.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.trans.rules;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.expr.XPathContextMajor;
12 import net.sf.saxon.expr.instruct.ParameterSet;
13 import net.sf.saxon.expr.instruct.TailCall;
14 import net.sf.saxon.expr.parser.Location;
15 import net.sf.saxon.om.*;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.type.Type;
18
19 /**
20 * The rule set introduced in XSLT 3.0, which (for any kind of node) simply ignores the node
21 * and its descendants.
22 */
23 public class DeepSkipRuleSet implements BuiltInRuleSet {
24
25 private static DeepSkipRuleSet THE_INSTANCE = new DeepSkipRuleSet();
26
27 /**
28 * Get the singleton instance of this class
29 *
30 * @return the singleton instance
31 */
32
33 public static DeepSkipRuleSet getInstance() {
34 return THE_INSTANCE;
35 }
36
37 private DeepSkipRuleSet() {
38 }
39
40 /**
41 * Perform the built-in template action for a given item.
42 * @param item the item to be processed
43 * @param parameters the parameters supplied to apply-templates
44 * @param tunnelParams the tunnel parameters to be passed through
45 * @param context the dynamic evaluation context
46 * @param locationId location of the instruction (apply-templates, apply-imports etc) that caused
47 * the built-in template to be invoked @throws net.sf.saxon.trans.XPathException
48 */
49
50 public void process(Item item, ParameterSet parameters,
51 ParameterSet tunnelParams, XPathContext context,
52 Location locationId) throws XPathException {
53 if (item instanceof NodeInfo && ((NodeInfo) item).getNodeKind() == Type.DOCUMENT) {
54 XPathContextMajor c2 = context.newContext();
55 c2.setOrigin(this);
56 c2.trackFocus(((NodeInfo) item).iterateAxis(AxisInfo.CHILD));
57 c2.setCurrentComponent(c2.getCurrentMode());
58 TailCall tc = c2.getCurrentMode().getActor().applyTemplates(parameters, tunnelParams, c2, locationId);
59 while (tc != null) {
60 tc = tc.processLeavingTail();
61 }
62 }
63 // otherwise, do nothing
64 }
65
66
67 /**
68 * Identify this built-in rule set
69 *
70 * @return "deep-skip"
71 */
72
73 @Override
74 public String getName() {
75 return "deep-skip";
76 }
77
78 /**
79 * Get the default action for unmatched nodes
80 *
81 * @param nodeKind the node kind
82 * @return the default action for unmatched element nodes: one of DEEP_COPY, APPLY_TEMPLATES, DEEP_SKIP, FAIL
83 */
84 public int[] getActionForParentNodes(int nodeKind) {
85 if (nodeKind == Type.DOCUMENT) {
86 return new int[]{APPLY_TEMPLATES_TO_CHILDREN};
87 } else {
88 return new int[]{DEEP_SKIP};
89 }
90 }
91 }