Xalan-C++ API Reference 1.12.0
StylesheetRoot.hpp
Go to the documentation of this file.
1/*
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 */
18#if !defined(XALAN_STYLESHEETROOT_HEADER_GUARD)
19#define XALAN_STYLESHEETROOT_HEADER_GUARD
20
21
22
23// Base include file. Must be first.
24#include "XSLTDefinitions.hpp"
25
26
27
28#include "Stylesheet.hpp"
29
30
31
34
35
36
38
39
40
42
43
44
45namespace XALAN_CPP_NAMESPACE {
46
47
48
49class ElemAttributeSet;
50class StylesheetConstructionContext;
51class XalanText;
52class XSLTResultTarget;
53
54
57
58/**
59 * This acts as the stylesheet root of the stylesheet
60 * tree, and holds values that are shared by all
61 * stylesheets in the tree.
62 */
64{
65public:
66
68
70
71 typedef XalanMap<const XalanQName*,
73
74 /**
75 * Construct a Stylesheet from a Document.
76 *
77 * @param baseIdentifier document identifier
78 * @param constructionContext context for construction of object
79 */
83
84 virtual
86
87 static StylesheetRoot*
89 MemoryManager& theManager,
92
93 MemoryManager&
95 {
96 return m_version.getMemoryManager();
97 }
98 /**
99 * Called after construction is completed.
100 */
101 virtual void
103
104 /**
105 * Transform the source tree to the output in the given result tree target.
106 *
107 * @param inputSource The input source
108 * @param outputTarget The output result target
109 * @param constructionContext context for construction of object
110 */
111 void
116
117 /**
118 * Have the stylesheet create the appropriate FormatterListener,
119 * based on the XSLTResultTarget provided. setupFormatterListener
120 * also calls setFormatterListener() on the execution context
121 * instance. setupFormatterListener() is done automatically by
122 * process(), but this is provided as an escape, to allow for
123 * changing the FormatterListener on-the-fly.
124 *
125 * @param outputTarget The output source tree
126 * @param constructionContext context for construction of object
127 * @return a pointer to the new FormatterListener instance.
128 */
133
134 /**
135 * Return the output method that was specified in the stylesheet.
136 * The returned value is one of FormatterLister::eFormat values.
137 *
138 * @return value of output method
139 */
142 {
143 return m_outputMethod;
144 }
145
146 bool
148 {
149 return getOutputMethod() == FormatterListener::OUTPUT_METHOD_NONE ? false : true;
150 }
151
152 /**
153 * Get the output version string that was specified in the
154 * xsl:output element
155 *
156 * @return output version string
157 */
160 {
161 theResult.assign(m_version);
162
163 return theResult;
164 }
165
166 /**
167 * Determine if output indenting was specified in the
168 * xsl:output element
169 *
170 * @return true to indent
171 */
172 bool
174 {
175 return m_indentResult == eIndentNoImplicit ||
176 m_indentResult == eIndentNoExplicit ? false : true;
177 }
178
179 /**
180 * Determine if output indenting should be
181 * enabled for HTML output. Semantically,
182 * this implies the output method is implicit,
183 * not explicit, but we don't really check that.
184 *
185 * @return true to indent
186 */
187 bool
189 {
190 return m_indentResult == eIndentNoExplicit ? false : true;
191 }
192
193 /**
194 * Get the output encoding string that was specified in the
195 * xsl:output element
196 *
197 * @return encoding string
198 */
201 {
202 theResult.assign(m_encoding);
203
204 return theResult;
205 }
206
207 /**
208 * Get the media-type string that was specified in the
209 * xsl:output element
210 *
211 * @return media type string
212 */
215 {
216 theResult.assign(m_mediatype);
217
218 return theResult;
219 }
220
221 /**
222 * Get the doctype-system-id string that was specified in the
223 * xsl:output element
224 *
225 * @return document type string
226 */
229 {
230 theResult.assign(m_doctypeSystem);
231
232 return theResult;
233 }
234
235 /**
236 * Get the doctype-public-id string that was specified in the
237 * xsl:output element
238 *
239 * @return document type public id string
240 */
243 {
244 theResult.assign(m_doctypePublic);
245
246 return theResult;
247 }
248
249 /**
250 * Determine whether to output XML declarations.
251 *
252 * @return true to output declarations
253 */
254 bool
256 {
257 return m_omitxmlDecl;
258 }
259
260 /**
261 * Get the standalone string that was specified in the
262 * xsl:output element.(either "yes" or "no")
263 *
264 * @return standalone string
265 */
268 {
269 theResult.assign(m_standalone);
270
271 return theResult;
272 }
273
274 /**
275 * Get the template representing the default rule for text.
276 *
277 * @return pointer to template rule for text
278 */
281 {
282 return m_defaultTextRule;
283 }
284
285 /**
286 * Get the template representing the default rule.
287 *
288 * @return pointer to default template rule
289 */
292 {
293 return m_defaultRule;
294 }
295
296 /**
297 * Get the template representing the default root rule.
298 *
299 * @return pointer to default root template rule
300 */
303 {
304 return m_defaultRootRule;
305 }
306
307 /**
308 * Process the "xsl:output" element.
309 *
310 * @param name name of element
311 * @param atts attribute list for element
312 * @param constructionContext context for construction of object
313 */
314 void
316 const XalanDOMChar* name,
317 const AttributeListType& atts,
319
320 /**
321 * Retrieve the stack of imported stylesheets.
322 *
323 * @return stack of URIs for stylesheets
324 */
327 {
328 return m_importStack;
329 }
330
331 /**
332 * Retrieve the stack of imported stylesheets.
333 *
334 * @return const stack of URIs for stylesheets
335 */
336 const URLStackType&
338 {
339 return m_importStack;
340 }
341
342 /**
343 * Change the value of the flag for indenting results.
344 *
345 * @param bIndent true to indent results
346 */
347 void
349 {
350 m_indentResult = bIndent == true ? eIndentYesExplicit : eIndentNoExplicit;
351 }
352
353 /**
354 * Change the value of the output method, one of the
355 * FormatterListener::eFormat values.
356 *
357 * @param meth new method number
358 */
359 void
361 {
362 m_outputMethod = meth;
363 }
364
365 bool
367 {
368 assert((m_hasCDATASectionElems == false && m_cdataSectionElems.empty() == true ) ||
369 ( m_hasCDATASectionElems == true && m_cdataSectionElems.empty() == false));
370
371 return m_hasCDATASectionElems;
372 }
373
374 /**
375 * Determine if a QName is in the list of CDATA section
376 * element QNames.
377 *
378 * @param theQName The QName of the element to check.
379 * @return true or false
380 */
381 bool
383
384 /**
385 * Given a valid element key, return the corresponding node list.
386 *
387 * @param context context node
388 * @param qname qname of the key, which must match the 'name'
389 * attribute on xsl:key
390 * @param ref value that must match the value found by the
391 * 'match' attribute on xsl:key
392 * @param resolver resolver for namespace resolution
393 * @param nodelist A node list to contain the nodes found
394 * @param executionContext The current execution context
395 * @param theKeysTable The table of keys to search.
396 */
397 void
400 const XalanQName& qname,
401 const XalanDOMString& ref,
405 const Locator* locator,
407
408 unsigned long
410 {
411 return m_elemNumberNextID++;
412 }
413
414 unsigned long
416 {
417 return m_elemNumberNextID;
418 }
419
420 bool
422 {
423 return m_hasStripOrPreserveSpace;
424 }
425
426 /**
427 * Check to see if a whitespace text node should be stripped from
428 * the source tree.
429 *
430 * @param theNode The text node to check.
431 */
432 bool
434 {
435 if (hasPreserveOrStripSpaceElements() == true &&
436 theNode.isWhitespace() == true)
437 {
438 return internalShouldStripSourceNode(theNode);
439 }
440
441 return false;
442 }
443
444 void
446
447#if !defined(XALAN_RECURSIVE_STYLESHEET_EXECUTION)
448 /**
449 * Get the nth attribute set with the specified name.
450 *
451 * @param execution context for executing this stylesheet
452 * @param theQName the name of the attribute set
453 * @param matchingIndex index of the attribute set with the specified name
454 * @param theLocator the locator
455 * @returns a pointer to the attribute, 0 if no matching attribute set
456 */
457 const ElemAttributeSet*
460 const XalanQName& theQName,
462 const Locator* theLocator) const;
463#else
464 void
467 const XalanQName& theQName,
468 const Locator* theLocator) const;
469#endif
470
471
472private:
473
474 /**
475 * Choose the encoding to use.
476 *
477 * @param outputTarget The output result target
478 *
479 * @return The chosen encoding
480 */
481 const XalanDOMString&
482 getEncoding(const XSLTResultTarget& outputTarget) const;
483
484 /**
485 * Create the default rule if needed.
486 *
487 * @param constructionContext context for construction of object
488 */
489 void
491
492 /**
493 * Check to see if a whitespace text node should be stripped from
494 * the source tree.
495 *
496 * @param theNode The text node to check.
497 */
498 bool
499 internalShouldStripSourceNode(const XalanText& theNode) const;
500
501 /**
502 * The version tells the version of XML to be used for outputting the result tree,
503 * as specified in xsl:output.
504 */
505 XalanDOMString m_version;
506
507 enum eIndentType { eIndentNoImplicit, eIndentNoExplicit, eIndentYesImplicit, eIndentYesExplicit };
508
509 /**
510 * indent-result is by default no, which means an XSL processor must not
511 * change the whitespace on output.
512 */
513 eIndentType m_indentResult;
514
515 /**
516 * The encoding attribute specifies the preferred encoding to use
517 * for outputting the result tree.
518 */
519 XalanDOMString m_encoding;
520
521 /**
522 * The media-type attribute is applicable for the xml output method.
523 * The default value for the media-type attribute is text/xml.
524 */
525 XalanDOMString m_mediatype;
526
527 /**
528 * If the doctype-system-id attribute is specified, the xml output method should
529 * output a document type declaration immediately before the first element.
530 * The name following <!DOCTYPE should be the name of the first element.
531 */
532 XalanDOMString m_doctypeSystem;
533
534 /**
535 * If doctype-public-id attribute is also specified, then the xml output
536 * method should output PUBLIC followed by the public identifier and then
537 * the system identifier; otherwise, it should output SYSTEM followed by
538 * the system identifier. The internal subset should be empty. The
539 * doctype-public-id attribute should be ignored unless the doctype-system-id
540 * attribute is specified.
541 */
542 XalanDOMString m_doctypePublic;
543
544 /**
545 * Tells whether or not to output an XML declaration.
546 */
547 bool m_omitxmlDecl;
548
549 /**
550 * Tells what the xmldecl should specify for the standalone value.
551 */
552 XalanDOMString m_standalone;
553
554 /**
555 * The URL that belongs to the result namespace.
556 * @serial
557 */
558 XalanDOMString m_resultNameSpaceURL;
559
560 /**
561 * The output method as specified in xsl:output.
562 */
563 FormatterListener::eFormat m_outputMethod;
564
565 /**
566 * Vector of qnames that specifies elements that should be formatted
567 * as CDATA.
568 */
569 XalanQNameVectorType m_cdataSectionElems;
570
571 bool m_hasCDATASectionElems;
572
573 /**
574 * A stack of who's importing whom is needed in order to detect
575 * a recursive include or import, which is an error.
576 */
577 URLStackType m_importStack;
578
579
580 /**
581 * The default template to use for text nodes if we don't find
582 * anything else. This is initialized in initDefaultRule().
583 */
584 ElemTemplateElement* m_defaultTextRule;
585
586 /**
587 * The default template to use if we don't find anything
588 * else. This is initialized in initDefaultRule().
589 */
590 ElemTemplateElement* m_defaultRule;
591
592 /**
593 * The default template to use for the root if we don't find
594 * anything else. This is initialized in initDefaultRule().
595 */
596 ElemTemplateElement* m_defaultRootRule;
597
598 /**
599 * This is set to true if an xsl:key directive is found.
600 */
601 bool m_needToBuildKeysTable;
602
603 /**
604 * This is set to true if URLs should be escaped in HTML output (the default)
605 */
606 bool m_outputEscapeURLs;
607
608 /**
609 * The amount to indent. The default is -1, which indicates not to indent.
610 */
611 int m_indentAmount;
612
613 /**
614 * This is set to true if we should omit the META tag in HTML output (the default is false)
615 */
616 bool m_omitMETATag;
617
618 /**
619 * This is set to true if we should omit the META tag in HTML output (the default is false)
620 */
621 unsigned long m_elemNumberNextID;
622
623 /**
624 * A lookup table of all attribute sets.
625 */
626 AttributeSetMapType m_attributeSetsMap;
627
628 /**
629 * true if there are any whitespace strip or preserve
630 * elements.
631 */
632 bool m_hasStripOrPreserveSpace;
633
634
635 // Not implemented...
637
639 operator=(const StylesheetRoot&);
640
641 bool
642 operator==(const StylesheetRoot&) const;
643};
644
645
646
647}
648
649
650
651#endif // XALAN_STYLESHEETROOT_HEADER_GUARD
#define XALAN_XSLT_EXPORT
#define XALAN_USES_MEMORY_MANAGER(Type)
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
A SAX-based formatter interface for the XSL processor.
Local implementation of MutableNodeRefList.
This class defines an interface for classes that resolve namespace prefixes to their URIs.
This acts as the stylesheet root of the stylesheet tree, and holds values that are shared by all styl...
ElemTemplateElement * getDefaultRule() const
Get the template representing the default rule.
StylesheetRoot(const XalanDOMString &baseIdentifier, StylesheetConstructionContext &constructionContext)
Construct a Stylesheet from a Document.
const URLStackType & getImportStack() const
Retrieve the stack of imported stylesheets.
unsigned long getElemNumberCount() const
AttributeSetVectorTypeDecl AttributeSetVectorType
void setIndentResult(bool bIndent)
Change the value of the flag for indenting results.
bool getOmitOutputXMLDecl() const
Determine whether to output XML declarations.
bool getHTMLOutputIndent() const
Determine if output indenting should be enabled for HTML output.
virtual void postConstruction(StylesheetConstructionContext &constructionContext)
Called after construction is completed.
void setOutputMethod(FormatterListener::eFormat meth)
Change the value of the output method, one of the FormatterListener::eFormat values.
XalanDOMString & getOutputVersion(XalanDOMString &theResult) const
Get the output version string that was specified in the xsl:output element.
FormatterListener * setupFormatterListener(XSLTResultTarget &outputTarget, StylesheetExecutionContext &executionContext) const
Have the stylesheet create the appropriate FormatterListener, based on the XSLTResultTarget provided.
XalanDOMString & getOutputMediaType(XalanDOMString &theResult) const
Get the media-type string that was specified in the xsl:output element.
unsigned long getNextElemNumberID()
ElemTemplateElement * getDefaultRootRule() const
Get the template representing the default root rule.
const ElemAttributeSet * getAttributeSet(StylesheetExecutionContext &theExecutionContext, const XalanQName &theQName, size_type matchingIndex, const Locator *theLocator) const
Get the nth attribute set with the specified name.
static StylesheetRoot * create(MemoryManager &theManager, const XalanDOMString &baseIdentifier, StylesheetConstructionContext &constructionContext)
XalanDOMString & getOutputEncoding(XalanDOMString &theResult) const
Get the output encoding string that was specified in the xsl:output element.
void addAttributeSet(ElemAttributeSet &theAttributeSet)
ElemTemplateElement * getDefaultTextRule() const
Get the template representing the default rule for text.
void processOutputSpec(const XalanDOMChar *name, const AttributeListType &atts, StylesheetConstructionContext &constructionContext)
Process the "xsl:output" element.
void getNodeSetByKey(XalanNode *context, const XalanQName &qname, const XalanDOMString &ref, const PrefixResolver &resolver, MutableNodeRefList &nodelist, StylesheetExecutionContext &executionContext, const Locator *locator, KeyTablesTableType &theKeysTable) const
Given a valid element key, return the corresponding node list.
XalanVector< const XalanQName * > XalanQNameVectorType
XalanDOMString & getOutputDoctypeSystem(XalanDOMString &theResult) const
Get the doctype-system-id string that was specified in the xsl:output element.
void process(XalanNode *sourceTree, XSLTResultTarget &outputTarget, StylesheetExecutionContext &executionContext) const
Transform the source tree to the output in the given result tree target.
XalanDOMString & getOutputDoctypePublic(XalanDOMString &theResult) const
Get the doctype-public-id string that was specified in the xsl:output element.
FormatterListener::eFormat getOutputMethod() const
Return the output method that was specified in the stylesheet.
XalanMap< const XalanQName *, AttributeSetVectorType > AttributeSetMapType
URLStackType & getImportStack()
Retrieve the stack of imported stylesheets.
bool isCDATASectionElementName(const XalanQName &theQName) const
Determine if a QName is in the list of CDATA section element QNames.
XalanDOMString & getOutputStandalone(XalanDOMString &theResult) const
Get the standalone string that was specified in the xsl:output element.
bool hasCDATASectionElements() const
MemoryManager & getMemoryManager()
bool hasPreserveOrStripSpaceElements() const
bool shouldStripSourceNode(const XalanText &theNode) const
Check to see if a whitespace text node should be stripped from the source tree.
bool getOutputIndent() const
Determine if output indenting was specified in the xsl:output element.
This class represents the base stylesheet or an "import" stylesheet.
Xalan implementation of a hashtable.
Definition XalanMap.hpp:187
Class to represent a qualified name.
size_t size_type
Definition XalanMap.hpp:46
xercesc::AttributeList AttributeListType
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)