19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: ElemValueOf.java 468643 2006-10-28 06:56:03Z minchau $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xalan.templates;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.TransformerException;
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources;
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.transformer.TransformerImpl;
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTM;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.serializer.SerializationHandler;
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.Expression;
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPath;
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathContext;
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XObject;
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.SAXException;
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Implement xsl:value-of.
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <pre>
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <!ELEMENT xsl:value-of EMPTY>
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <!ATTLIST xsl:value-of
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *   select %expr; #REQUIRED
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *   disable-output-escaping (yes|no) "no"
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * >
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </pre>
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#value-of">value-of in XSLT Specification</a>
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage advanced
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class ElemValueOf extends ElemTemplateElement
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static final long serialVersionUID = 3490728458007586786L;
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The select expression to be executed.
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @serial
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private XPath m_selectExpression = null;
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * True if the pattern is a simple ".".
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @serial
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private boolean m_isDot = false;
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the "select" attribute.
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The required select attribute is an expression; this expression
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * is evaluated and the resulting object is converted to a
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * string as if by a call to the string function.
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param v The value to set for the "select" attribute.
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setSelect(XPath v)
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != v)
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      String s = v.getPatternString();
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_isDot = (null != s) && s.equals(".");
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_selectExpression = v;
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the "select" attribute.
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The required select attribute is an expression; this expression
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * is evaluated and the resulting object is converted to a
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * string as if by a call to the string function.
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The value of the "select" attribute.
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public XPath getSelect()
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_selectExpression;
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Tells if this element should disable escaping.
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @serial
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private boolean m_disableOutputEscaping = false;
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the "disable-output-escaping" attribute.
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Normally, the xml output method escapes & and < (and
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * possibly other characters) when outputting text nodes.
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This ensures that the output is well-formed XML. However,
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * it is sometimes convenient to be able to produce output
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * that is almost, but not quite well-formed XML; for
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * example, the output may include ill-formed sections
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * which are intended to be transformed into well-formed
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XML by a subsequent non-XML aware process. For this reason,
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XSLT provides a mechanism for disabling output escaping.
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * An xsl:value-of or xsl:text element may have a
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * disable-output-escaping attribute; the allowed values
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * are yes or no; the default is no; if the value is yes,
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * then a text node generated by instantiating the xsl:value-of
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * or xsl:text element should be output without any escaping.
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param v The value to set for the "disable-output-escaping" attribute.
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setDisableOutputEscaping(boolean v)
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_disableOutputEscaping = v;
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the "disable-output-escaping" attribute.
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Normally, the xml output method escapes & and < (and
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * possibly other characters) when outputting text nodes.
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This ensures that the output is well-formed XML. However,
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * it is sometimes convenient to be able to produce output
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * that is almost, but not quite well-formed XML; for
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * example, the output may include ill-formed sections
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * which are intended to be transformed into well-formed
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XML by a subsequent non-XML aware process. For this reason,
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * XSLT provides a mechanism for disabling output escaping.
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * An xsl:value-of or xsl:text element may have a
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * disable-output-escaping attribute; the allowed values
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * are yes or no; the default is no; if the value is yes,
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * then a text node generated by instantiating the xsl:value-of
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * or xsl:text element should be output without any escaping.
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#disable-output-escaping">disable-output-escaping in XSLT Specification</a>
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The value of the "disable-output-escaping" attribute.
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public boolean getDisableOutputEscaping()
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_disableOutputEscaping;
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get an integer representation of the element type.
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return An integer representation of the element, defined in the
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *     Constants class.
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.apache.xalan.templates.Constants
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getXSLToken()
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return Constants.ELEMNAME_VALUEOF;
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This function is called after everything else has been
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * recomposed, and allows the template to set remaining
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * values that may be based on some other property that
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * depends on recomposition.
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * NEEDSDOC @param sroot
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws TransformerException
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void compose(StylesheetRoot sroot) throws TransformerException
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    super.compose(sroot);
1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    java.util.Vector vnames = sroot.getComposeState().getVariableNames();
1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != m_selectExpression)
1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_selectExpression.fixupVariables(
1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        vnames, sroot.getComposeState().getGlobalsSize());
1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the node name.
1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The node name
1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public String getNodeName()
1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return Constants.ELEMNAME_VALUEOF_STRING;
1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Execute the string expression and copy the text to the
1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * result tree.
2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The required select attribute is an expression; this expression
2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * is evaluated and the resulting object is converted to a string
2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * as if by a call to the string function. The string specifies
2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the string-value of the created text node. If the string is
2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * empty, no text node will be created. The created text node will
2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * be merged with any adjacent text nodes.
2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#value-of">value-of in XSLT Specification</a>
2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param transformer non-null reference to the the current transform-time state.
2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws TransformerException
2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void execute(TransformerImpl transformer) throws TransformerException
2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    XPathContext xctxt = transformer.getXPathContext();
2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    SerializationHandler rth = transformer.getResultTreeHandler();
2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    try
2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      // Optimize for "."
2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        xctxt.pushNamespaceContext(this);
2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        int current = xctxt.getCurrentNode();
2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        xctxt.pushCurrentNodeAndExpression(current, current);
2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (m_disableOutputEscaping)
2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          rth.processingInstruction(
2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        try
2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          Expression expr = m_selectExpression.getExpression();
2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            expr.executeCharsToContentHandler(xctxt, rth);
2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        finally
2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          if (m_disableOutputEscaping)
2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            rth.processingInstruction(
2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson              javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          xctxt.popNamespaceContext();
2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          xctxt.popCurrentNodeAndExpression();
2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    catch (SAXException se)
2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      throw new TransformerException(se);
2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    catch (RuntimeException re) {
2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	TransformerException te = new TransformerException(re);
2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	te.setLocator(this);
2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	throw te;
2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Add a child to the child list.
2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param newChild Child to add to children list
2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return Child just added to children list
2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws DOMException
2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public ElemTemplateElement appendChild(ElemTemplateElement newChild)
2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    error(XSLTErrorResources.ER_CANNOT_ADD,
2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          new Object[]{ newChild.getNodeName(),
2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        this.getNodeName() });  //"Can not add " +((ElemTemplateElement)newChild).m_elemName +
2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //" to " + this.m_elemName);
2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return null;
2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Call the children visitors.
2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param visitor The visitor whose appropriate method will be called.
2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs)
2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	if(callAttrs)
2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  		m_selectExpression.getExpression().callVisitors(m_selectExpression, visitor);
2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    super.callChildVisitors(visitor, callAttrs);
2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
290