Debian Codegraph @

net/sf/saxon/style/XSLValueOf.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.style;
9
10 import net.sf.saxon.Configuration;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.StringLiteral;
13 import net.sf.saxon.expr.instruct.ValueOf;
14 import net.sf.saxon.om.AttributeCollection;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.type.TypeHierarchy;
17 import net.sf.saxon.value.StringValue;
18 import net.sf.saxon.value.Whitespace;
19
20
21 /**
22 * An xsl:value-of element in the stylesheet. <br>
23 * The xsl:value-of element takes attributes:<ul>
24 * <li>a mandatory attribute select="expression".
25 * This must be a valid String expression</li>
26 * <li>an optional disable-output-escaping attribute, value "yes" or "no"</li>
27 * <li>an optional separator attribute</li>
28 * </ul>
29 */
30
31 public final class XSLValueOf extends XSLLeafNodeConstructor {
32
33 private boolean disable = false;
34 /*@Nullable*/ private Expression separator;
35
36
37 public void prepareAttributes() throws XPathException {
38
39 String selectAtt = null;
40 String disableAtt = null;
41 String separatorAtt = null;
42
43 AttributeCollection atts = getAttributeList();
44
45 for (int a = 0; a < atts.getLength(); a++) {
46 String f = atts.getQName(a);
47 if (f.equals("disable-output-escaping")) {
48 disableAtt = Whitespace.trim(atts.getValue(a));
49 } else if (f.equals("select")) {
50 selectAtt = atts.getValue(a);
51 select = makeExpression(selectAtt, a);
52 } else if (f.equals("separator")) {
53 separatorAtt = atts.getValue(a);
54 separator = makeAttributeValueTemplate(separatorAtt, a);
55 } else {
56 checkUnknownAttribute(atts.getNodeName(a));
57 }
58 }
59
60 if (disableAtt != null) {
61 disable = processBooleanAttribute("disable-output-escaping", disableAtt);
62 }
63 }
64
65 public void validate(ComponentDeclaration decl) throws XPathException {
66 super.validate(decl);
67 select = typeCheck("select", select);
68 separator = typeCheck("separator", separator);
69 }
70
71 /**
72 * Get the error code to be returned when the element has a select attribute but is not empty.
73 *
74 * @return the error code defined for this condition, for this particular instruction
75 */
76
77 protected String getErrorCodeForSelectPlusContent() {
78 return "XTSE0870";
79 }
80
81 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
82 Configuration config = getConfiguration();
83 final TypeHierarchy th = config.getTypeHierarchy();
84 if (separator == null && select != null && xPath10ModeIsEnabled()) {
85 // Handle XSLT 1.0 backwards compatibility
86 select = config.getTypeChecker(true).processValueOf(select, config);
87 } else {
88 if (separator == null) {
89 if (select == null) {
90 separator = new StringLiteral(StringValue.EMPTY_STRING);
91 } else {
92 separator = new StringLiteral(StringValue.SINGLE_SPACE);
93 }
94 }
95 }
96 ValueOf inst = new ValueOf(select, disable, false);
97 inst.setRetainedStaticContext(makeRetainedStaticContext());
98 compileContent(exec, decl, inst, separator);
99 return inst;
100 }
101
102 }
103