2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
* $Id: Stylesheet.java,v 1.2 2009/12/10 03:18:29 matthewoliver Exp $
21
package org.apache.xalan.templates;
23
import java.io.IOException;
24
import java.io.ObjectInputStream;
25
import java.io.ObjectOutputStream;
26
import java.util.Hashtable;
27
import java.util.Stack;
28
import java.util.Vector;
30
import javax.xml.transform.SourceLocator;
31
import javax.xml.transform.TransformerException;
33
import org.apache.xml.dtm.DTM;
34
import org.apache.xml.utils.QName;
35
import org.apache.xml.utils.StringVector;
36
import org.apache.xml.utils.SystemIDResolver;
39
* Represents a stylesheet element.
40
* <p>All properties in this class have a fixed form of bean-style property
41
* accessors for all properties that represent XSL attributes or elements.
42
* These properties have setter method names accessed generically by the
43
* processor, and so these names must be fixed according to the system
44
* defined in the <a href="XSLTAttributeDef#getSetterMethodName">getSetterMethodName</a>
47
* <!ENTITY % top-level "
51
* | xsl:preserve-space
54
* | xsl:decimal-format
59
* | xsl:namespace-alias
60
* %non-xsl-top-level;)*)
63
* <!ENTITY % top-level-atts '
64
* extension-element-prefixes CDATA #IMPLIED
65
* exclude-result-prefixes CDATA #IMPLIED
67
* version NMTOKEN #REQUIRED
68
* xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
72
* <!ELEMENT xsl:stylesheet %top-level;>
73
* <!ATTLIST xsl:stylesheet %top-level-atts;>
75
* <!ELEMENT xsl:transform %top-level;>
76
* <!ATTLIST xsl:transform %top-level-atts;>
79
* @see <a href="http://www.w3.org/TR/xslt#section-Stylesheet-Structure">section-Stylesheet-Structure in XSLT Specification</a>
81
public class Stylesheet extends ElemTemplateElement
82
implements java.io.Serializable /* , Document */
84
static final long serialVersionUID = 2085337282743043776L;
87
* Constructor for a Stylesheet.
88
* @param parent The including or importing stylesheet.
90
public Stylesheet(Stylesheet parent)
95
m_stylesheetParent = parent;
96
m_stylesheetRoot = parent.getStylesheetRoot();
101
* Get the owning stylesheet. This looks up the
102
* inheritance chain until it calls getStylesheet
103
* on a Stylesheet object, which will return itself.
105
* @return The owning stylesheet, itself.
107
public Stylesheet getStylesheet()
113
* Tell if this can be cast to a StylesheetComposed, meaning, you
114
* can ask questions from getXXXComposed functions.
116
* @return False if this is not a StylesheetComposed
118
public boolean isAggregatedType()
124
* Tell if this is the root of the stylesheet tree.
126
* @return False is this is not the root of the stylesheet tree.
128
public boolean isRoot()
134
* Extension to be used when serializing to disk.
136
public static final String STYLESHEET_EXT = ".lxc";
139
* Read the stylesheet from a serialization stream.
141
* @param stream Input stream to read from
143
* @throws IOException
144
* @throws TransformerException
146
private void readObject(ObjectInputStream stream)
147
throws IOException, TransformerException
150
// System.out.println("Reading Stylesheet");
153
stream.defaultReadObject();
155
catch (ClassNotFoundException cnfe)
157
throw new TransformerException(cnfe);
160
// System.out.println("Done reading Stylesheet");
164
* Write out the given output stream
167
* @param stream The output stream to write out
169
* @throws IOException
171
private void writeObject(ObjectOutputStream stream) throws IOException
174
// System.out.println("Writing Stylesheet");
175
stream.defaultWriteObject();
177
// System.out.println("Done writing Stylesheet");
180
//============== XSLT Properties =================
183
* The "xmlns:xsl" property.
186
private String m_XmlnsXsl;
189
* Set the "xmlns:xsl" property.
190
* @see <a href="http://www.w3.org/TR/xslt#xslt-namespace">xslt-namespace in XSLT Specification</a>
192
* @param v The value to be set for the "xmlns:xsl" property.
194
public void setXmlnsXsl(String v)
200
* Get the "xmlns:xsl" property.
201
* @see <a href="http://www.w3.org/TR/xslt#xslt-namespace">xslt-namespace in XSLT Specification</a>
203
* @return The value of the "xmlns:xsl" property.
205
public String getXmlnsXsl()
211
* The "extension-element-prefixes" property, actually contains URIs.
214
private StringVector m_ExtensionElementURIs;
217
* Set the "extension-element-prefixes" property.
218
* @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
220
* @param v The value to be set for the "extension-element-prefixes"
221
* property: a vector of extension element URIs.
223
public void setExtensionElementPrefixes(StringVector v)
225
m_ExtensionElementURIs = v;
229
* Get and "extension-element-prefix" property.
230
* @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
232
* @param i Index of extension element URI in list
234
* @return The extension element URI at the given index
236
* @throws ArrayIndexOutOfBoundsException
238
public String getExtensionElementPrefix(int i)
239
throws ArrayIndexOutOfBoundsException
242
if (null == m_ExtensionElementURIs)
243
throw new ArrayIndexOutOfBoundsException();
245
return m_ExtensionElementURIs.elementAt(i);
249
* Get the number of "extension-element-prefixes" Strings.
250
* @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
252
* @return Number of URIs in the list
254
public int getExtensionElementPrefixCount()
256
return (null != m_ExtensionElementURIs)
257
? m_ExtensionElementURIs.size() : 0;
261
* Find out if this contains a given "extension-element-prefix" property.
262
* @see <a href="http://www.w3.org/TR/xslt#extension-element">extension-element in XSLT Specification</a>
264
* @param uri URI of extension element to look for
266
* @return True if the given URI was found in the list
268
public boolean containsExtensionElementURI(String uri)
271
if (null == m_ExtensionElementURIs)
274
return m_ExtensionElementURIs.contains(uri);
278
* The "exclude-result-prefixes" property.
281
private StringVector m_ExcludeResultPrefixs;
284
* Set the "exclude-result-prefixes" property.
285
* The designation of a namespace as an excluded namespace is
286
* effective within the subtree of the stylesheet rooted at
287
* the element bearing the exclude-result-prefixes or
288
* xsl:exclude-result-prefixes attribute; a subtree rooted
289
* at an xsl:stylesheet element does not include any stylesheets
290
* imported or included by children of that xsl:stylesheet element.
291
* @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
293
* @param v A StringVector of prefixes to exclude
295
public void setExcludeResultPrefixes(StringVector v)
297
m_ExcludeResultPrefixs = v;
301
* Get an "exclude-result-prefix" property.
302
* The designation of a namespace as an excluded namespace is
303
* effective within the subtree of the stylesheet rooted at
304
* the element bearing the exclude-result-prefixes or
305
* xsl:exclude-result-prefixes attribute; a subtree rooted
306
* at an xsl:stylesheet element does not include any stylesheets
307
* imported or included by children of that xsl:stylesheet element.
308
* @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
310
* @param i Index of prefix to get in list
312
* @return Prefix to be excluded at the given index
314
* @throws ArrayIndexOutOfBoundsException
316
public String getExcludeResultPrefix(int i)
317
throws ArrayIndexOutOfBoundsException
320
if (null == m_ExcludeResultPrefixs)
321
throw new ArrayIndexOutOfBoundsException();
323
return m_ExcludeResultPrefixs.elementAt(i);
327
* Get the number of "exclude-result-prefixes" Strings.
328
* @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
330
* @return The number of prefix strings to be excluded.
332
public int getExcludeResultPrefixCount()
334
return (null != m_ExcludeResultPrefixs)
335
? m_ExcludeResultPrefixs.size() : 0;
339
* Get whether or not the passed prefix is contained flagged by
340
* the "exclude-result-prefixes" property.
341
* @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
343
* @param prefix non-null reference to prefix that might be excluded.
344
* @param uri reference to namespace that prefix maps to
346
* @return true if the prefix should normally be excluded.>
348
public boolean containsExcludeResultPrefix(String prefix, String uri)
351
if (null == m_ExcludeResultPrefixs || uri == null )
354
// This loop is ok here because this code only runs during
355
// stylesheet compile time.
356
for (int i =0; i< m_ExcludeResultPrefixs.size(); i++)
358
if (uri.equals(getNamespaceForPrefix(m_ExcludeResultPrefixs.elementAt(i))))
364
/* if (prefix.length() == 0)
365
prefix = Constants.ATTRVAL_DEFAULT_PREFIX;
367
return m_ExcludeResultPrefixs.contains(prefix); */
377
* Set the "id" property.
378
* @see <a href="http://www.w3.org/TR/xslt#section-Embedding-Stylesheets">section-Embedding-Stylesheets in XSLT Specification</a>
380
* @param v Value for the "id" property.
382
public void setId(String v)
388
* Get the "id" property.
389
* @see <a href="http://www.w3.org/TR/xslt#section-Embedding-Stylesheets">section-Embedding-Stylesheets in XSLT Specification</a>
391
* @return The value of the "id" property.
393
public String getId()
399
* The "version" property.
402
private String m_Version;
405
* Whether or not the stylesheet is in "Forward Compatibility Mode"
408
private boolean m_isCompatibleMode = false;
411
* Set the "version" property.
412
* @see <a href="http://www.w3.org/TR/xslt#forwards">forwards in XSLT Specification</a>
414
* @param v Value for the "version" property.
416
public void setVersion(String v)
419
m_isCompatibleMode = (Double.valueOf(v).doubleValue() > Constants.XSLTVERSUPPORTED);
423
* Get whether or not the stylesheet is in "Forward Compatibility Mode"
425
* @return true if in forward compatible mode, false otherwise
427
public boolean getCompatibleMode()
429
return m_isCompatibleMode;
433
* Get the "version" property.
434
* @see <a href="http://www.w3.org/TR/xslt#forwards">forwards in XSLT Specification</a>
436
* @return The value of the "version" property.
438
public String getVersion()
444
* The "xsl:import" list.
447
private Vector m_imports;
450
* Add a stylesheet to the "import" list.
451
* @see <a href="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
453
* @param v Stylesheet to add to the import list
455
public void setImport(StylesheetComposed v)
458
if (null == m_imports)
459
m_imports = new Vector();
461
// I'm going to insert the elements in backwards order,
462
// so I can walk them 0 to n.
463
m_imports.addElement(v);
467
* Get a stylesheet from the "import" list.
468
* @see <a href="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
470
* @param i Index of the stylesheet to get
472
* @return The stylesheet at the given index
474
* @throws ArrayIndexOutOfBoundsException
476
public StylesheetComposed getImport(int i)
477
throws ArrayIndexOutOfBoundsException
480
if (null == m_imports)
481
throw new ArrayIndexOutOfBoundsException();
483
return (StylesheetComposed) m_imports.elementAt(i);
487
* Get the number of imported stylesheets.
488
* @see <a href="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
490
* @return the number of imported stylesheets.
492
public int getImportCount()
494
return (null != m_imports) ? m_imports.size() : 0;
498
* The "xsl:include" properties.
501
private Vector m_includes;
504
* Add a stylesheet to the "include" list.
505
* @see <a href="http://www.w3.org/TR/xslt#include">include in XSLT Specification</a>
507
* @param v Stylesheet to add to the "include" list
509
public void setInclude(Stylesheet v)
512
if (null == m_includes)
513
m_includes = new Vector();
515
m_includes.addElement(v);
519
* Get the stylesheet at the given in index in "include" list
520
* @see <a href="http://www.w3.org/TR/xslt#include">include in XSLT Specification</a>
522
* @param i Index of stylesheet to get
524
* @return Stylesheet at the given index
526
* @throws ArrayIndexOutOfBoundsException
528
public Stylesheet getInclude(int i) throws ArrayIndexOutOfBoundsException
531
if (null == m_includes)
532
throw new ArrayIndexOutOfBoundsException();
534
return (Stylesheet) m_includes.elementAt(i);
538
* Get the number of included stylesheets.
539
* @see <a href="http://www.w3.org/TR/xslt#import">import in XSLT Specification</a>
541
* @return the number of included stylesheets.
543
public int getIncludeCount()
545
return (null != m_includes) ? m_includes.size() : 0;
549
* Table of tables of element decimal-format.
550
* @see DecimalFormatProperties
553
Stack m_DecimalFormatDeclarations;
556
* Process the xsl:decimal-format element.
558
* @param edf Decimal-format element to push into stack
560
public void setDecimalFormat(DecimalFormatProperties edf)
563
if (null == m_DecimalFormatDeclarations)
564
m_DecimalFormatDeclarations = new Stack();
566
// Elements are pushed in by order of importance
567
// so that when recomposed, they get overiden properly.
568
m_DecimalFormatDeclarations.push(edf);
572
* Get an "xsl:decimal-format" property.
574
* @see DecimalFormatProperties
575
* @see <a href="http://www.w3.org/TR/xslt#format-number">format-number in XSLT Specification</a>
577
* @param name The qualified name of the decimal format property.
578
* @return null if not found, otherwise a DecimalFormatProperties
579
* object, from which you can get a DecimalFormatSymbols object.
581
public DecimalFormatProperties getDecimalFormat(QName name)
584
if (null == m_DecimalFormatDeclarations)
587
int n = getDecimalFormatCount();
589
for (int i = (n - 1); i >= 0; i++)
591
DecimalFormatProperties dfp = getDecimalFormat(i);
593
if (dfp.getName().equals(name))
601
* Get an "xsl:decimal-format" property.
602
* @see <a href="http://www.w3.org/TR/xslt#format-number">format-number in XSLT Specification</a>
603
* @see DecimalFormatProperties
605
* @param i Index of decimal-format property in stack
607
* @return The decimal-format property at the given index
609
* @throws ArrayIndexOutOfBoundsException
611
public DecimalFormatProperties getDecimalFormat(int i)
612
throws ArrayIndexOutOfBoundsException
615
if (null == m_DecimalFormatDeclarations)
616
throw new ArrayIndexOutOfBoundsException();
618
return (DecimalFormatProperties) m_DecimalFormatDeclarations.elementAt(i);
622
* Get the number of xsl:decimal-format declarations.
623
* @see DecimalFormatProperties
625
* @return the number of xsl:decimal-format declarations.
627
public int getDecimalFormatCount()
629
return (null != m_DecimalFormatDeclarations)
630
? m_DecimalFormatDeclarations.size() : 0;
634
* The "xsl:strip-space" properties,
635
* A lookup table of all space stripping elements.
638
private Vector m_whitespaceStrippingElements;
641
* Set the "xsl:strip-space" properties.
642
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
644
* @param wsi WhiteSpaceInfo element to add to list
646
public void setStripSpaces(WhiteSpaceInfo wsi)
649
if (null == m_whitespaceStrippingElements)
651
m_whitespaceStrippingElements = new Vector();
654
m_whitespaceStrippingElements.addElement(wsi);
658
* Get an "xsl:strip-space" property.
659
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
661
* @param i Index of WhiteSpaceInfo to get
663
* @return WhiteSpaceInfo at given index
665
* @throws ArrayIndexOutOfBoundsException
667
public WhiteSpaceInfo getStripSpace(int i) throws ArrayIndexOutOfBoundsException
670
if (null == m_whitespaceStrippingElements)
671
throw new ArrayIndexOutOfBoundsException();
673
return (WhiteSpaceInfo) m_whitespaceStrippingElements.elementAt(i);
677
* Get the number of "xsl:strip-space" properties.
678
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
680
* @return the number of "xsl:strip-space" properties.
682
public int getStripSpaceCount()
684
return (null != m_whitespaceStrippingElements)
685
? m_whitespaceStrippingElements.size() : 0;
689
* The "xsl:preserve-space" property,
690
* A lookup table of all space preserving elements.
693
private Vector m_whitespacePreservingElements;
696
* Set the "xsl:preserve-space" property.
697
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
699
* @param wsi WhiteSpaceInfo element to add to list
701
public void setPreserveSpaces(WhiteSpaceInfo wsi)
704
if (null == m_whitespacePreservingElements)
706
m_whitespacePreservingElements = new Vector();
709
m_whitespacePreservingElements.addElement(wsi);
713
* Get a "xsl:preserve-space" property.
714
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
716
* @param i Index of WhiteSpaceInfo to get
718
* @return WhiteSpaceInfo at the given index
720
* @throws ArrayIndexOutOfBoundsException
722
public WhiteSpaceInfo getPreserveSpace(int i) throws ArrayIndexOutOfBoundsException
725
if (null == m_whitespacePreservingElements)
726
throw new ArrayIndexOutOfBoundsException();
728
return (WhiteSpaceInfo) m_whitespacePreservingElements.elementAt(i);
732
* Get the number of "xsl:preserve-space" properties.
733
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
735
* @return the number of "xsl:preserve-space" properties.
737
public int getPreserveSpaceCount()
739
return (null != m_whitespacePreservingElements)
740
? m_whitespacePreservingElements.size() : 0;
744
* The "xsl:output" properties. This is a vector of OutputProperties objects.
747
private Vector m_output;
750
* Set the "xsl:output" property.
751
* @see <a href="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
753
* @param v non-null reference to the OutputProperties object to be
754
* added to the collection.
756
public void setOutput(OutputProperties v)
758
if (null == m_output)
760
m_output = new Vector();
763
m_output.addElement(v);
767
* Get an "xsl:output" property.
768
* @see <a href="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
770
* @param i Index of OutputFormatExtended to get
772
* @return non-null reference to an OutputProperties object.
774
* @throws ArrayIndexOutOfBoundsException
776
public OutputProperties getOutput(int i) throws ArrayIndexOutOfBoundsException
779
if (null == m_output)
780
throw new ArrayIndexOutOfBoundsException();
782
return (OutputProperties) m_output.elementAt(i);
786
* Get the number of "xsl:output" properties.
787
* @see <a href="http://www.w3.org/TR/xslt#output">output in XSLT Specification</a>
789
* @return The number of OutputProperties objects contained in this stylesheet.
791
public int getOutputCount()
793
return (null != m_output)
794
? m_output.size() : 0;
798
* The "xsl:key" property.
801
private Vector m_keyDeclarations;
804
* Set the "xsl:key" property.
805
* @see <a href="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
807
* @param v KeyDeclaration element to add to the list of key declarations
809
public void setKey(KeyDeclaration v)
812
if (null == m_keyDeclarations)
813
m_keyDeclarations = new Vector();
815
m_keyDeclarations.addElement(v);
819
* Get an "xsl:key" property.
820
* @see <a href="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
822
* @param i Index of KeyDeclaration element to get
824
* @return KeyDeclaration element at given index in list
826
* @throws ArrayIndexOutOfBoundsException
828
public KeyDeclaration getKey(int i) throws ArrayIndexOutOfBoundsException
831
if (null == m_keyDeclarations)
832
throw new ArrayIndexOutOfBoundsException();
834
return (KeyDeclaration) m_keyDeclarations.elementAt(i);
838
* Get the number of "xsl:key" properties.
839
* @see <a href="http://www.w3.org/TR/xslt#key">key in XSLT Specification</a>
841
* @return the number of "xsl:key" properties.
843
public int getKeyCount()
845
return (null != m_keyDeclarations) ? m_keyDeclarations.size() : 0;
849
* The "xsl:attribute-set" property.
852
private Vector m_attributeSets;
855
* Set the "xsl:attribute-set" property.
856
* @see <a href="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
858
* @param attrSet ElemAttributeSet to add to the list of attribute sets
860
public void setAttributeSet(ElemAttributeSet attrSet)
863
if (null == m_attributeSets)
865
m_attributeSets = new Vector();
868
m_attributeSets.addElement(attrSet);
872
* Get an "xsl:attribute-set" property.
873
* @see <a href="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
875
* @param i Index of ElemAttributeSet to get in list
877
* @return ElemAttributeSet at the given index
879
* @throws ArrayIndexOutOfBoundsException
881
public ElemAttributeSet getAttributeSet(int i)
882
throws ArrayIndexOutOfBoundsException
885
if (null == m_attributeSets)
886
throw new ArrayIndexOutOfBoundsException();
888
return (ElemAttributeSet) m_attributeSets.elementAt(i);
892
* Get the number of "xsl:attribute-set" properties.
893
* @see <a href="http://www.w3.org/TR/xslt#attribute-sets">attribute-sets in XSLT Specification</a>
895
* @return the number of "xsl:attribute-set" properties.
897
public int getAttributeSetCount()
899
return (null != m_attributeSets) ? m_attributeSets.size() : 0;
903
* The "xsl:variable" and "xsl:param" properties.
906
private Vector m_topLevelVariables;
909
* Set the "xsl:variable" property.
910
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
912
* @param v ElemVariable object to add to list of top level variables
914
public void setVariable(ElemVariable v)
917
if (null == m_topLevelVariables)
918
m_topLevelVariables = new Vector();
920
m_topLevelVariables.addElement(v);
924
* Get an "xsl:variable" or "xsl:param" property.
925
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
927
* @param qname non-null reference to the qualified name of the variable.
929
* @return The ElemVariable with the given name in the list or null
931
public ElemVariable getVariableOrParam(QName qname)
934
if (null != m_topLevelVariables)
936
int n = getVariableOrParamCount();
938
for (int i = 0; i < n; i++)
940
ElemVariable var = (ElemVariable) getVariableOrParam(i);
942
if (var.getName().equals(qname))
952
* Get an "xsl:variable" property.
953
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
955
* @param qname Qualified name of the xsl:variable to get
957
* @return reference to the variable named by qname, or null if not found.
959
public ElemVariable getVariable(QName qname)
962
if (null != m_topLevelVariables)
964
int n = getVariableOrParamCount();
966
for (int i = 0; i < n; i++)
968
ElemVariable var = getVariableOrParam(i);
969
if((var.getXSLToken() == Constants.ELEMNAME_VARIABLE) &&
970
(var.getName().equals(qname)))
979
* Get an "xsl:variable" property.
980
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
982
* @param i Index of variable to get in the list
984
* @return ElemVariable at the given index in the list
986
* @throws ArrayIndexOutOfBoundsException
988
public ElemVariable getVariableOrParam(int i) throws ArrayIndexOutOfBoundsException
991
if (null == m_topLevelVariables)
992
throw new ArrayIndexOutOfBoundsException();
994
return (ElemVariable) m_topLevelVariables.elementAt(i);
998
* Get the number of "xsl:variable" properties.
999
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1001
* @return the number of "xsl:variable" properties.
1003
public int getVariableOrParamCount()
1005
return (null != m_topLevelVariables) ? m_topLevelVariables.size() : 0;
1009
* Set an "xsl:param" property.
1010
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1012
* @param v A non-null ElemParam reference.
1014
public void setParam(ElemParam v)
1020
* Get an "xsl:param" property.
1021
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1023
* @param qname non-null reference to qualified name of the parameter.
1025
* @return ElemParam with the given name in the list or null
1027
public ElemParam getParam(QName qname)
1030
if (null != m_topLevelVariables)
1032
int n = getVariableOrParamCount();
1034
for (int i = 0; i < n; i++)
1036
ElemVariable var = getVariableOrParam(i);
1037
if((var.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE) &&
1038
(var.getName().equals(qname)))
1039
return (ElemParam)var;
1047
* The "xsl:template" properties.
1050
private Vector m_templates;
1053
* Set an "xsl:template" property.
1054
* @see <a href="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a>
1056
* @param v ElemTemplate to add to list of templates
1058
public void setTemplate(ElemTemplate v)
1061
if (null == m_templates)
1062
m_templates = new Vector();
1064
m_templates.addElement(v);
1065
v.setStylesheet(this);
1069
* Get an "xsl:template" property.
1070
* @see <a href="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a>
1072
* @param i Index of ElemTemplate in the list to get
1074
* @return ElemTemplate at the given index in the list
1076
* @throws TransformerException
1078
public ElemTemplate getTemplate(int i) throws TransformerException
1081
if (null == m_templates)
1082
throw new ArrayIndexOutOfBoundsException();
1084
return (ElemTemplate) m_templates.elementAt(i);
1088
* Get the number of "xsl:template" properties.
1089
* @see <a href="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules in XSLT Specification</a>
1091
* @return the number of "xsl:template" properties.
1093
public int getTemplateCount()
1095
return (null != m_templates) ? m_templates.size() : 0;
1099
* The "xsl:namespace-alias" properties.
1102
private Vector m_prefix_aliases;
1105
* Set the "xsl:namespace-alias" property.
1106
* @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
1108
* @param na NamespaceAlias elemeent to add to the list
1110
public void setNamespaceAlias(NamespaceAlias na)
1113
if (m_prefix_aliases == null)
1114
m_prefix_aliases = new Vector();
1116
m_prefix_aliases.addElement(na);
1120
* Get an "xsl:namespace-alias" property.
1121
* @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
1123
* @param i Index of NamespaceAlias element to get from the list
1125
* @return NamespaceAlias element at the given index in the list
1127
* @throws ArrayIndexOutOfBoundsException
1129
public NamespaceAlias getNamespaceAlias(int i)
1130
throws ArrayIndexOutOfBoundsException
1133
if (null == m_prefix_aliases)
1134
throw new ArrayIndexOutOfBoundsException();
1136
return (NamespaceAlias) m_prefix_aliases.elementAt(i);
1140
* Get the number of "xsl:namespace-alias" properties.
1141
* @see <a href="http://www.w3.org/TR/xslt#top-level-variables">top-level-variables in XSLT Specification</a>
1143
* @return the number of "xsl:namespace-alias" properties.
1145
public int getNamespaceAliasCount()
1147
return (null != m_prefix_aliases) ? m_prefix_aliases.size() : 0;
1151
* The "non-xsl-top-level" properties.
1154
private Hashtable m_NonXslTopLevel;
1157
* Set found a non-xslt element.
1158
* @see <a href="http://www.w3.org/TR/xslt#stylesheet-element">stylesheet-element in XSLT Specification</a>
1160
* @param name Qualified name of the element
1161
* @param obj The element object
1163
public void setNonXslTopLevel(QName name, Object obj)
1166
if (null == m_NonXslTopLevel)
1167
m_NonXslTopLevel = new Hashtable();
1169
m_NonXslTopLevel.put(name, obj);
1173
* Get a non-xslt element.
1174
* @see <a href="http://www.w3.org/TR/xslt#stylesheet-element">stylesheet-element in XSLT Specification</a>
1176
* @param name Qualified name of the element to get
1178
* @return The object associate with the given name
1180
public Object getNonXslTopLevel(QName name)
1182
return (null != m_NonXslTopLevel) ? m_NonXslTopLevel.get(name) : null;
1185
// =========== End top-level XSLT properties ===========
1188
* The base URL of the XSL document.
1191
private String m_href = null;
1193
/** The doctype-public element.
1195
private String m_publicId;
1197
/** The doctype-system element.
1199
private String m_systemId;
1202
* Get the base identifier with which this stylesheet is associated.
1204
* @return the base identifier with which this stylesheet is associated.
1206
public String getHref()
1212
* Set the base identifier with which this stylesheet is associated.
1214
* @param baseIdent the base identifier with which this stylesheet is associated.
1216
public void setHref(String baseIdent)
1222
* Set the location information for this element.
1224
* @param locator SourceLocator object with location information
1226
public void setLocaterInfo(SourceLocator locator)
1229
if (null != locator)
1231
m_publicId = locator.getPublicId();
1232
m_systemId = locator.getSystemId();
1234
if (null != m_systemId)
1238
m_href = SystemIDResolver.getAbsoluteURI(m_systemId, null);
1240
catch (TransformerException se)
1243
// Ignore this for right now
1247
super.setLocaterInfo(locator);
1252
* The root of the stylesheet, where all the tables common
1253
* to all stylesheets are kept.
1256
private StylesheetRoot m_stylesheetRoot;
1259
* Get the root of the stylesheet, where all the tables common
1260
* to all stylesheets are kept.
1262
* @return the root of the stylesheet
1264
public StylesheetRoot getStylesheetRoot()
1266
return m_stylesheetRoot;
1270
* Set the root of the stylesheet, where all the tables common
1271
* to all stylesheets are kept.
1273
* @param v the root of the stylesheet
1275
public void setStylesheetRoot(StylesheetRoot v)
1277
m_stylesheetRoot = v;
1281
* The parent of the stylesheet. This will be null if this
1282
* is the root stylesheet.
1285
private Stylesheet m_stylesheetParent;
1288
* Get the parent of the stylesheet. This will be null if this
1289
* is the root stylesheet.
1291
* @return the parent of the stylesheet.
1293
public Stylesheet getStylesheetParent()
1295
return m_stylesheetParent;
1299
* Set the parent of the stylesheet. This should be null if this
1300
* is the root stylesheet.
1302
* @param v the parent of the stylesheet.
1304
public void setStylesheetParent(Stylesheet v)
1306
m_stylesheetParent = v;
1310
* Get the owning aggregated stylesheet, or this
1311
* stylesheet if it is aggregated.
1313
* @return the owning aggregated stylesheet or itself
1315
public StylesheetComposed getStylesheetComposed()
1318
Stylesheet sheet = this;
1320
while (!sheet.isAggregatedType())
1322
sheet = sheet.getStylesheetParent();
1325
return (StylesheetComposed) sheet;
1329
* Get the type of the node. We'll pretend we're a Document.
1331
* @return the type of the node: document node.
1333
public short getNodeType()
1335
return DTM.DOCUMENT_NODE;
1339
* Get an integer representation of the element type.
1341
* @return An integer representation of the element, defined in the
1343
* @see org.apache.xalan.templates.Constants
1345
public int getXSLToken()
1347
return Constants.ELEMNAME_STYLESHEET;
1351
* Return the node name.
1353
* @return The node name
1355
public String getNodeName()
1357
return Constants.ELEMNAME_STYLESHEET_STRING;
1361
* Replace an "xsl:template" property.
1362
* This is a hook for CompilingStylesheetHandler, to allow
1363
* us to access a template, compile it, instantiate it,
1364
* and replace the original with the compiled instance.
1365
* ADDED 9/5/2000 to support compilation experiment
1367
* @param v Compiled template to replace with
1368
* @param i Index of template to be replaced
1370
* @throws TransformerException
1372
public void replaceTemplate(ElemTemplate v, int i) throws TransformerException
1375
if (null == m_templates)
1376
throw new ArrayIndexOutOfBoundsException();
1378
replaceChild(v, (ElemTemplateElement)m_templates.elementAt(i));
1379
m_templates.setElementAt(v, i);
1380
v.setStylesheet(this);
1384
* Call the children visitors.
1385
* @param visitor The visitor whose appropriate method will be called.
1387
protected void callChildVisitors(XSLTVisitor visitor, boolean callAttrs)
1389
int s = getImportCount();
1390
for (int j = 0; j < s; j++)
1392
getImport(j).callVisitors(visitor);
1395
s = getIncludeCount();
1396
for (int j = 0; j < s; j++)
1398
getInclude(j).callVisitors(visitor);
1401
s = getOutputCount();
1402
for (int j = 0; j < s; j++)
1404
visitor.visitTopLevelInstruction(getOutput(j));
1407
// Next, add in the attribute-set elements
1409
s = getAttributeSetCount();
1410
for (int j = 0; j < s; j++)
1412
ElemAttributeSet attrSet = getAttributeSet(j);
1413
if (visitor.visitTopLevelInstruction(attrSet))
1415
attrSet.callChildVisitors(visitor);
1418
// Now the decimal-formats
1420
s = getDecimalFormatCount();
1421
for (int j = 0; j < s; j++)
1423
visitor.visitTopLevelInstruction(getDecimalFormat(j));
1429
for (int j = 0; j < s; j++)
1431
visitor.visitTopLevelInstruction(getKey(j));
1434
// And the namespace aliases
1436
s = getNamespaceAliasCount();
1437
for (int j = 0; j < s; j++)
1439
visitor.visitTopLevelInstruction(getNamespaceAlias(j));
1442
// Next comes the templates
1444
s = getTemplateCount();
1445
for (int j = 0; j < s; j++)
1449
ElemTemplate template = getTemplate(j);
1450
if (visitor.visitTopLevelInstruction(template))
1452
template.callChildVisitors(visitor);
1455
catch (TransformerException te)
1457
throw new org.apache.xml.utils.WrappedRuntimeException(te);
1461
// Then, the variables
1463
s = getVariableOrParamCount();
1464
for (int j = 0; j < s; j++)
1466
ElemVariable var = getVariableOrParam(j);
1467
if (visitor.visitTopLevelVariableOrParamDecl(var))
1469
var.callChildVisitors(visitor);
1473
// And lastly the whitespace preserving and stripping elements
1475
s = getStripSpaceCount();
1476
for (int j = 0; j < s; j++)
1478
visitor.visitTopLevelInstruction(getStripSpace(j));
1481
s = getPreserveSpaceCount();
1482
for (int j = 0; j < s; j++)
1484
visitor.visitTopLevelInstruction(getPreserveSpace(j));
1487
if(null != m_NonXslTopLevel)
1489
java.util.Enumeration elements = m_NonXslTopLevel.elements();
1490
while(elements.hasMoreElements())
1492
ElemTemplateElement elem = (ElemTemplateElement)elements.nextElement();
1493
if (visitor.visitTopLevelInstruction(elem))
1495
elem.callChildVisitors(visitor);
1504
* Accept a visitor and call the appropriate method
1507
* @param visitor The visitor whose appropriate method will be called.
1508
* @return true if the children of the object should be visited.
1510
protected boolean accept(XSLTVisitor visitor)
1512
return visitor.visitStylesheet(this);