1 16 19 package org.apache.xalan.templates; 20 21 import javax.xml.transform.TransformerException ; 22 23 import org.apache.xalan.res.XSLTErrorResources; 24 import org.apache.xalan.transformer.TransformerImpl; 25 import org.apache.xml.utils.QName; 26 import org.apache.xpath.XPath; 27 import org.apache.xpath.XPathContext; 28 import org.apache.xpath.objects.XObject; 29 import org.apache.xpath.objects.XRTreeFrag; 30 import org.apache.xpath.objects.XString; 31 32 45 public class ElemWithParam extends ElemTemplateElement 46 { 47 51 int m_index; 52 53 58 private XPath m_selectPattern = null; 59 60 67 public void setSelect(XPath v) 68 { 69 m_selectPattern = v; 70 } 71 72 79 public XPath getSelect() 80 { 81 return m_selectPattern; 82 } 83 84 91 private QName m_qname = null; 92 93 int m_qnameID; 94 95 101 public void setName(QName v) 102 { 103 m_qname = v; 104 } 105 106 112 public QName getName() 113 { 114 return m_qname; 115 } 116 117 124 public int getXSLToken() 125 { 126 return Constants.ELEMNAME_WITHPARAM; 127 } 128 129 130 135 public String getNodeName() 136 { 137 return Constants.ELEMNAME_WITHPARAM_STRING; 138 } 139 140 146 public void compose(StylesheetRoot sroot) throws TransformerException 147 { 148 if(null == m_selectPattern 150 && org.apache.xalan.processor.TransformerFactoryImpl.m_optimize) 151 { 152 XPath newSelect = ElemVariable.rewriteChildToExpression(this); 153 if(null != newSelect) 154 m_selectPattern = newSelect; 155 } 156 m_qnameID = sroot.getComposeState().getQNameID(m_qname); 157 super.compose(sroot); 158 159 java.util.Vector vnames = sroot.getComposeState().getVariableNames(); 160 if(null != m_selectPattern) 161 m_selectPattern.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize()); 162 163 } 165 166 171 public void setParentElem(ElemTemplateElement p) 172 { 173 super.setParentElem(p); 174 p.m_hasVariableDecl = true; 175 } 176 177 187 public XObject getValue(TransformerImpl transformer, int sourceNode) 188 throws TransformerException 189 { 190 191 XObject var; 192 XPathContext xctxt = transformer.getXPathContext(); 193 194 xctxt.pushCurrentNode(sourceNode); 195 196 try 197 { 198 if (null != m_selectPattern) 199 { 200 var = m_selectPattern.execute(xctxt, sourceNode, this); 201 202 var.allowDetachToRelease(false); 203 204 if (TransformerImpl.S_DEBUG) 205 transformer.getTraceManager().fireSelectedEvent(sourceNode, this, 206 "select", m_selectPattern, var); 207 } 208 else if (null == getFirstChildElem()) 209 { 210 var = XString.EMPTYSTRING; 211 } 212 else 213 { 214 215 int df = transformer.transformToRTF(this); 217 218 var = new XRTreeFrag(df, xctxt, this); 219 } 220 } 221 finally 222 { 223 xctxt.popCurrentNode(); 224 } 225 226 return var; 227 } 228 229 233 protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs) 234 { 235 if(callAttrs && (null != m_selectPattern)) 236 m_selectPattern.getExpression().callVisitors(m_selectPattern, visitor); 237 super.callChildVisitors(visitor, callAttrs); 238 } 239 240 249 public ElemTemplateElement appendChild(ElemTemplateElement elem) 250 { 251 if (m_selectPattern != null) 253 { 254 error(XSLTErrorResources.ER_CANT_HAVE_CONTENT_AND_SELECT, 255 new Object []{"xsl:" + this.getNodeName()}); 256 return null; 257 } 258 return super.appendChild(elem); 259 } 260 261 262 } 263 | Popular Tags |