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: ElemVariable.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.transformer.TransformerImpl;
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.utils.QName;
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPath;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.XPathContext;
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XObject;
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XRTreeFrag;
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XRTreeFragSelectWrapper;
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xpath.objects.XString;
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xalan.res.XSLTErrorResources;
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Implement xsl:variable.
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <pre>
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <!ELEMENT xsl:variable %template;>
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <!ATTLIST xsl:variable
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *   name %qname; #REQUIRED
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *   select %expr; #IMPLIED
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * >
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </pre>
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see <a href="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage advanced
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class ElemVariable extends ElemTemplateElement
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static final long serialVersionUID = 9111131075322790061L;
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Constructor ElemVariable
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public ElemVariable(){}
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This is the index into the stack frame.
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected int m_index;
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The stack frame size for this variable if it is a global variable
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * that declares an RTF, which is equal to the maximum number
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * of variables that can be declared in the variable at one time.
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  int m_frameSize = -1;
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Sets the relative position of this variable within the stack frame (if local)
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * or the global area (if global).  Note that this should be called only for
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * global variables since the local position is computed in the compose() method.
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setIndex(int index)
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_index = index;
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * If this element is not at the top-level, get the relative position of the
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * variable into the stack frame.  If this variable is at the top-level, get
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the relative position within the global area.
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getIndex()
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_index;
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The value of the "select" attribute.
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @serial
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private XPath m_selectPattern;
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the "select" attribute.
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * If the variable-binding element has a select attribute,
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * then the value of the attribute must be an expression and
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the value of the variable is the object that results from
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * evaluating the expression. In this case, the content
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * of the variable must be empty.
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param v Value to set for the "select" attribute.
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setSelect(XPath v)
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_selectPattern = v;
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the "select" attribute.
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * If the variable-binding element has a select attribute,
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * then the value of the attribute must be an expression and
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the value of the variable is the object that results from
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * evaluating the expression. In this case, the content
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * of the variable must be empty.
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return Value of the "select" attribute.
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public XPath getSelect()
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_selectPattern;
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * The value of the "name" attribute.
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @serial
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected QName m_qname;
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the "name" attribute.
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Both xsl:variable and xsl:param have a required name
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * attribute, which specifies the name of the variable. The
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * value of the name attribute is a QName, which is expanded
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * as described in [2.4 Qualified Names].
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#qname">qname in XSLT Specification</a>
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param v Value to set for the "name" attribute.
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setName(QName v)
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_qname = v;
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the "name" attribute.
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Both xsl:variable and xsl:param have a required name
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * attribute, which specifies the name of the variable. The
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * value of the name attribute is a QName, which is expanded
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * as described in [2.4 Qualified Names].
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#qname">qname in XSLT Specification</a>
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return Value of the "name" attribute.
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public QName getName()
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_qname;
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Tells if this is a top-level variable or param, or not.
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @serial
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  private boolean m_isTopLevel = false;
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set if this is a top-level variable or param, or not.
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param v Boolean indicating whether this is a top-level variable
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * or param, or not.
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setIsTopLevel(boolean v)
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_isTopLevel = v;
1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get if this is a top-level variable or param, or not.
1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return Boolean indicating whether this is a top-level variable
1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * or param, or not.
1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public boolean getIsTopLevel()
1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return m_isTopLevel;
1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get an integer representation of the element type.
1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return An integer representation of the element, defined in the
1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *     Constants class.
1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see org.apache.xalan.templates.Constants
1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public int getXSLToken()
2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return Constants.ELEMNAME_VARIABLE;
2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Return the node name.
2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return The node name
2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public String getNodeName()
2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return Constants.ELEMNAME_VARIABLE_STRING;
2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Copy constructor.
2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param param An element created from an xsl:variable
2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws TransformerException
2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public ElemVariable(ElemVariable param) throws TransformerException
2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_selectPattern = param.m_selectPattern;
2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_qname = param.m_qname;
2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    m_isTopLevel = param.m_isTopLevel;
2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // m_value = param.m_value;
2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // m_varContext = param.m_varContext;
2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Execute a variable declaration and push it onto the variable stack.
2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @see <a href="http://www.w3.org/TR/xslt#variables">variables in XSLT Specification</a>
2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param transformer non-null reference to the the current transform-time state.
2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws TransformerException
2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void execute(TransformerImpl transformer) throws TransformerException
2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    int sourceNode = transformer.getXPathContext().getCurrentNode();
2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    XObject var = getValue(transformer, sourceNode);
2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // transformer.getXPathContext().getVarStack().pushVariable(m_qname, var);
2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    transformer.getXPathContext().getVarStack().setLocalVariable(m_index, var);
2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Get the XObject representation of the variable.
2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param transformer non-null reference to the the current transform-time state.
2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return the XObject representation of the variable.
2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws TransformerException
2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public XObject getValue(TransformerImpl transformer, int sourceNode)
2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws TransformerException
2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    XObject var;
2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    XPathContext xctxt = transformer.getXPathContext();
2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    xctxt.pushCurrentNode(sourceNode);
2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    try
2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (null != m_selectPattern)
2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        var = m_selectPattern.execute(xctxt, sourceNode, this);
2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        var.allowDetachToRelease(false);
2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else if (null == getFirstChildElem())
2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        var = XString.EMPTYSTRING;
2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else
2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // Use result tree fragment.
2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // Global variables may be deferred (see XUnresolvedVariable) and hence
2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // need to be assigned to a different set of DTMs than local variables
2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // so they aren't popped off the stack on return from a template.
2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        int df;
2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		// Bugzilla 7118: A variable set via an RTF may create local
2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		// variables during that computation. To keep them from overwriting
2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		// variables at this level, push a new variable stack.
2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		////// PROBLEM: This is provoking a variable-used-before-set
2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		////// problem in parameters. Needs more study.
2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		try
2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		{
2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson			//////////xctxt.getVarStack().link(0);
2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson			if(m_parentNode instanceof Stylesheet) // Global variable
3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson				df = transformer.transformToGlobalRTF(this);
3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson			else
3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson				df = transformer.transformToRTF(this);
3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	}
3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		finally{
3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson			//////////////xctxt.getVarStack().unlink();
3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson			}
3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        var = new XRTreeFrag(df, xctxt, this);
3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    finally
3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      xctxt.popCurrentNode();
3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return var;
3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This function is called after everything else has been
3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * recomposed, and allows the template to set remaining
3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * values that may be based on some other property that
3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * depends on recomposition.
3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void compose(StylesheetRoot sroot) throws TransformerException
3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // See if we can reduce an RTF to a select with a string expression.
3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(null == m_selectPattern
3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson       && sroot.getOptimizer())
3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      XPath newSelect = rewriteChildToExpression(this);
3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if(null != newSelect)
3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        m_selectPattern = newSelect;
3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    StylesheetRoot.ComposeState cstate = sroot.getComposeState();
3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // This should be done before addVariableName, so we don't have visibility
3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // to the variable now being defined.
3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    java.util.Vector vnames = cstate.getVariableNames();
3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(null != m_selectPattern)
3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_selectPattern.fixupVariables(vnames, cstate.getGlobalsSize());
3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Only add the variable if this is not a global.  If it is a global,
3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // it was already added by stylesheet root.
3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(!(m_parentNode instanceof Stylesheet) && m_qname != null)
3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      m_index = cstate.addVariableName(m_qname) - cstate.getGlobalsSize();
3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    else if (m_parentNode instanceof Stylesheet)
3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	// If this is a global, then we need to treat it as if it's a xsl:template,
3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	// and count the number of variables it contains.  So we set the count to
3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	// zero here.
3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson		cstate.resetStackFrameSize();
3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // This has to be done after the addVariableName, so that the variable
3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // pushed won't be immediately popped again in endCompose.
3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    super.compose(sroot);
3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This after the template's children have been composed.  We have to get
3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * the count of how many variables have been declared, so we can do a link
3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * and unlink.
3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void endCompose(StylesheetRoot sroot) throws TransformerException
3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    super.endCompose(sroot);
3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if(m_parentNode instanceof Stylesheet)
3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	StylesheetRoot.ComposeState cstate = sroot.getComposeState();
3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	m_frameSize = cstate.getFrameSize();
3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    	cstate.resetStackFrameSize();
3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson//  /**
3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson//   * This after the template's children have been composed.
3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson//   */
3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson//  public void endCompose() throws TransformerException
3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson//  {
3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson//    super.endCompose();
3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson//  }
3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * If the children of a variable is a single xsl:value-of or text literal,
3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * it is cheaper to evaluate this as an expression, so try and adapt the
3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * child an an expression.
3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param varElem Should be a ElemParam, ElemVariable, or ElemWithParam.
3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return An XPath if rewrite is possible, else null.
3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @throws TransformerException
4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  static XPath rewriteChildToExpression(ElemTemplateElement varElem)
4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          throws TransformerException
4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    ElemTemplateElement t = varElem.getFirstChildElem();
4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Down the line this can be done with multiple string objects using
4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // the concat function.
4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (null != t && null == t.getNextSiblingElem())
4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      int etype = t.getXSLToken();
4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      if (Constants.ELEMNAME_VALUEOF == etype)
4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        ElemValueOf valueof = (ElemValueOf) t;
4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // %TBD% I'm worried about extended attributes here.
4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (valueof.getDisableOutputEscaping() == false
4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                && valueof.getDOMBackPointer() == null)
4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          varElem.m_firstChild = null;
4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          return new XPath(new XRTreeFragSelectWrapper(valueof.getSelect().getExpression()));
4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      else if (Constants.ELEMNAME_TEXTLITERALRESULT == etype)
4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      {
4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        ElemTextLiteral lit = (ElemTextLiteral) t;
4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (lit.getDisableOutputEscaping() == false
4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                && lit.getDOMBackPointer() == null)
4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          String str = lit.getNodeValue();
4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          XString xstr = new XString(str);
4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          varElem.m_firstChild = null;
4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          return new XPath(new XRTreeFragSelectWrapper(xstr));
4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      }
4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return null;
4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * This function is called during recomposition to
4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * control how this element is composed.
4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param root The root stylesheet for this transformation.
4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void recompose(StylesheetRoot root)
4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    root.recomposeVariables(this);
4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Set the parent as an ElemTemplateElement.
4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param p This node's parent as an ElemTemplateElement
4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public void setParentElem(ElemTemplateElement p)
4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    super.setParentElem(p);
4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    p.m_hasVariableDecl = true;
4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Accept a visitor and call the appropriate method
4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * for this class.
4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param visitor The visitor whose appropriate method will be called.
4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return true if the children of the object should be visited.
4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected boolean accept(XSLTVisitor visitor)
4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	return visitor.visitVariableOrParamDecl(this);
4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Call the children visitors.
4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param visitor The visitor whose appropriate method will be called.
4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs)
4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	if(null != m_selectPattern)
4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  		m_selectPattern.getExpression().callVisitors(m_selectPattern, visitor);
4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    super.callChildVisitors(visitor, callAttrs);
4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Tell if this is a psuedo variable reference, declared by Xalan instead
4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * of by the user.
4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public boolean isPsuedoVar()
4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	java.lang.String ns = m_qname.getNamespaceURI();
4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	if((null != ns) && ns.equals(RedundentExprEliminator.PSUEDOVARNAMESPACE))
5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	{
5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  		if(m_qname.getLocalName().startsWith("#"))
5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  			return true;
5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	}
5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  	return false;
5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  /**
5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * Add a child to the child list. If the select attribute
5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * is present, an error will be raised.
5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @param elem New element to append to this element's children list
5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   *
5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * @return null if the select attribute was present, otherwise the
5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   * child just added to the child list
5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson   */
5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  public ElemTemplateElement appendChild(ElemTemplateElement elem)
5179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  {
5189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // cannot have content and select
5199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    if (m_selectPattern != null)
5209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
5219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      error(XSLTErrorResources.ER_CANT_HAVE_CONTENT_AND_SELECT,
5229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson          new Object[]{"xsl:" + this.getNodeName()});
5239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      return null;
5249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
5259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    return super.appendChild(elem);
5269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson  }
5279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
529