summaryrefslogtreecommitdiffstats
blob: cff2485b726148364befd56eeb4cca820645f83e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
<xsl:stylesheet version='1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns:doc='http://xsltsl.org/xsl/documentation/1.0'
  xmlns:markup='http://xsltsl.org/markup'
  xmlns:str='http://xsltsl.org/string'
  extension-element-prefixes='doc markup str'>

  <doc:reference xmlns=''>
    <referenceinfo>
      <releaseinfo role="meta">
	$Id: markup.xsl 3991 2004-11-10 06:51:55Z balls $
      </releaseinfo>
      <author>
	<surname>Ball</surname>
	<firstname>Steve</firstname>
      </author>
      <copyright>
	<year>2003</year>
	<year>2001</year>
	<holder>Steve Ball</holder>
      </copyright>
    </referenceinfo>

    <title>XML Markup Templates</title>

    <partintro>
      <section>
	<title>Introduction</title>

	<para>This stylesheet module provides functions for generating literal XML markup.</para>

      </section>
    </partintro>

  </doc:reference>

  <doc:template name="markup:xml-declaration" xmlns="">
    <refpurpose>Create an XML Declaration</refpurpose>

    <refdescription>
      <para>This template returns an XML Declaration.  Although the XSLT standard provides control over the generation of the XML Declaration, this template may be useful in circumstances where the values must be computed at runtime.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>version</term>
	  <listitem>
	    <para>Version number.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>standalone</term>
	  <listitem>
	    <para>Standalone indication.  Must be value "yes" or "no".</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>encoding</term>
	  <listitem>
	    <para>Character encoding.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns an XML Declaration as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:xml-declaration'>
    <xsl:param name='version' select="'1.0'"/>
    <xsl:param name='standalone'/>
    <xsl:param name='encoding'/>

    <xsl:text disable-output-escaping='yes'>&lt;?xml version="</xsl:text>
    <xsl:copy-of select="$version"/>
    <xsl:text>"</xsl:text>

    <xsl:choose>
      <xsl:when test="string-length($standalone) = 0"/>
      <xsl:when test='$standalone = "yes" or $standalone = "no"'>
        <xsl:text> standalone="</xsl:text>
        <xsl:copy-of select="$standalone"/>
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate="yes">invalid value "<xsl:value-of select="$standalone"/>" for standalone attribute</xsl:message>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:if test='string-length($encoding) &gt; 0'>
      <xsl:text> encoding="</xsl:text>
      <xsl:copy-of select='$encoding'/>
      <xsl:text>"</xsl:text>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>?&gt;
</xsl:text>
  </xsl:template>

  <doc:template name="markup:doctype-declaration" xmlns="">
    <refpurpose>Create a Document Type Declaration</refpurpose>

    <refdescription>
      <para>This template returns a Document Type Declaration.  Although the XSLT standard provides control over the generation of a Document Type Declaration, this template may be useful in circumstances where the values for the identifiers or the internal subset must be computed at runtime.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>docel</term>
	  <listitem>
	    <para>The name of the document element.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>publicid</term>
	  <listitem>
	    <para>The public identifier for the external DTD subset.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>systemid</term>
	  <listitem>
	    <para>The system identifier for the external DTD subset.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>internaldtd</term>
	  <listitem>
	    <para>The internal DTD subset.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns a Document Type Declaration as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:doctype-declaration'>
    <xsl:param name='docel'/>
    <xsl:param name='publicid'/>
    <xsl:param name='systemid'/>
    <xsl:param name='internaldtd'/>

    <xsl:if test='string-length($docel) = 0'>
      <xsl:message terminate='yes'>No document element specified</xsl:message>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE </xsl:text>
    <xsl:copy-of select="$docel"/>

    <xsl:call-template name='markup:external-identifier'>
      <xsl:with-param name='publicid' select='$publicid'/>
      <xsl:with-param name='systemid' select='$systemid'/>
      <xsl:with-param name='leading-space' select='true()'/>
    </xsl:call-template>

    <xsl:if test='string-length($internaldtd) &gt; 0'>
      <xsl:text> [</xsl:text>
      <xsl:copy-of select='$internaldtd'/>
      <xsl:text>]</xsl:text>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&gt;
</xsl:text>
  </xsl:template>

  <doc:template name="markup:element-declaration" xmlns="">
    <refpurpose>Create an Element Declaration</refpurpose>

    <refdescription>
      <para>This template returns an element declaration..</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>type</term>
	  <listitem>
	    <para>The element type.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>content-spec</term>
	  <listitem>
	    <para>The content specification.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns an element declaration as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:element-declaration'>
    <xsl:param name='type'/>
    <xsl:param name='content-spec' select="'ANY'"/>

    <xsl:if test='string-length($type) = 0'>
      <xsl:message terminate='yes'>element type must be specified</xsl:message>
    </xsl:if>
    <xsl:if test='string-length($content-spec) = 0'>
      <xsl:message terminate='yes'>content specification must be specified</xsl:message>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&lt;!ELEMENT </xsl:text>
    <xsl:copy-of select='$type'/>
    <xsl:text> </xsl:text>
    <xsl:copy-of select='$content-spec'/>
    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  </xsl:template>

  <doc:template name="markup:attlist-declaration" xmlns="">
    <refpurpose>Create an Attribute List Declaration</refpurpose>

    <refdescription>
      <para>This template returns an attribute list declaration.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>type</term>
	  <listitem>
	    <para>The element type.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>attr-defns</term>
	  <listitem>
	    <para>Attribute definitions.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns an attribute list declaration as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:attlist-declaration'>
    <xsl:param name='type'/>
    <xsl:param name='attr-defns'/>

    <xsl:if test='string-length($type) = 0'>
      <xsl:message terminate='yes'>element type must be specified</xsl:message>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&lt;!ATTLIST </xsl:text>
    <xsl:copy-of select='$type'/>
    <xsl:text> </xsl:text>
    <xsl:copy-of select='$attr-defns'/>
    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  </xsl:template>

  <doc:template name="markup:attribute-definition" xmlns="">
    <refpurpose>Create an Attribute Definition</refpurpose>

    <refdescription>
      <para>This template returns an attribute definition.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>name</term>
	  <listitem>
	    <para>The attribute name.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>type</term>
	  <listitem>
	    <para>The attribute type.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>default</term>
	  <listitem>
	    <para>The attribute default.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns an attribute definition as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:attribute-definition'>
    <xsl:param name='name'/>
    <xsl:param name='type'/>
    <xsl:param name='default'/>

    <xsl:if test='string-length($name) = 0'>
      <xsl:message terminate='yes'>attribute name must be specified</xsl:message>
    </xsl:if>
    <xsl:if test='string-length($type) = 0'>
      <xsl:message terminate='yes'>attribute type must be specified</xsl:message>
    </xsl:if>
    <xsl:if test='string-length($default) = 0'>
      <xsl:message terminate='yes'>attribute default must be specified</xsl:message>
    </xsl:if>

    <xsl:text> </xsl:text>
    <xsl:copy-of select='$name'/>
    <xsl:text> </xsl:text>
    <xsl:copy-of select='$type'/>
    <xsl:text> </xsl:text>
    <xsl:copy-of select='$default'/>
  </xsl:template>

  <doc:template name="markup:entity-declaration" xmlns="">
    <refpurpose>Create an Entity Declaration</refpurpose>

    <refdescription>
      <para>This template returns an entity declaration.</para>
      <para>If the 'text' parameter is given a value, then an internal entity is created.  If either the 'publicid' or 'systemid' parameters are given a value then an external entity is created.  It is an error for the 'text' parameter to have value as well as the 'publicid', 'systemid' or 'notation' parameters.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>name</term>
	  <listitem>
	    <para>The entity name.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>parameter</term>
	  <listitem>
	    <para>Boolean value to determine whether a parameter entity is created.  Default is 'false()'.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>text</term>
	  <listitem>
	    <para>The replacement text.  Must be a string.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>nodes</term>
	  <listitem>
	    <para>The replacement text as a nodeset.  The nodeset is formatted as XML using the as-xml template.  If both text and nodes are specified then nodes takes precedence.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>publicid</term>
	  <listitem>
	    <para>The public identifier for an external entity.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>systemid</term>
	  <listitem>
	    <para>The system identifier for an external entity.</para>
	  </listitem>
	</varlistentry>
 	<varlistentry>
	  <term>notation</term>
	  <listitem>
	    <para>The notation for an external entity.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns an entity declaration as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:entity-declaration'>
    <xsl:param name='name'/>
    <xsl:param name='parameter' select='false()'/>
    <xsl:param name='text'/>
    <xsl:param name='nodes'/>
    <xsl:param name='publicid'/>
    <xsl:param name='systemid'/>
    <xsl:param name='notation'/>

    <xsl:if test='string-length($name) = 0'>
      <xsl:message terminate='yes'>entity name must be specified</xsl:message>
    </xsl:if>
    <xsl:if test='string-length($text) &gt; 0 and 
                  (string-length($publicid) &gt; 0 or
                   string-length($systemid) &gt; 0 or
                   string-length($notation) &gt; 0)'>
      <xsl:message terminate='yes'>both replacement text and external identifier specified</xsl:message>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&lt;!ENTITY </xsl:text>
    <xsl:copy-of select='$name'/>
    <xsl:text> </xsl:text>
    <xsl:if test="$parameter">
      <xsl:text>% </xsl:text>
    </xsl:if>

    <xsl:choose>
      <xsl:when test="$nodes">
        <xsl:call-template name='markup:quote-value'>
          <xsl:with-param name='value'>
            <xsl:call-template name="markup:as-xml">
              <xsl:with-param name="nodes" select="$nodes"/>
            </xsl:call-template>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test='$text'>
        <xsl:call-template name='markup:quote-value'>
          <xsl:with-param name='value' select='$text'/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name='markup:external-identifier'>
          <xsl:with-param name='publicid' select='$publicid'/>
          <xsl:with-param name='systemid' select='$systemid'/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:if test='$notation'>
      <xsl:text> NDATA "</xsl:text>
      <xsl:copy-of select='$notation'/>
      <xsl:text>"</xsl:text>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  </xsl:template>

  <doc:template name="markup:quote-value" xmlns="">
    <refpurpose>Quote an Attribute Value</refpurpose>

    <refdescription>
      <para>This template returns a quoted value.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>value</term>
	  <listitem>
	    <para>The value to quote.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns a quote value as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:quote-value'>
    <xsl:param name='value'/>

    <xsl:variable name="quoted">
      <xsl:call-template name='markup:quote-value-aux'>
        <xsl:with-param name='value' select='$value'/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:choose>
      <xsl:when test="contains($value, '&lt;')">
        <xsl:call-template name='str:subst'>
          <xsl:with-param name='text' select='$quoted'/>
          <xsl:with-param name='replace'>&lt;</xsl:with-param>
          <xsl:with-param name='with'>
            <xsl:text disable-output-escaping='yes'>&amp;lt;</xsl:text>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select='$quoted'/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name='markup:quote-value-aux'>
    <xsl:param name='value'/>

    <!-- Quoting hell! -->
    <xsl:variable name="quot">&quot;</xsl:variable>
    <xsl:variable name="apos">&apos;</xsl:variable>

    <xsl:choose>
      <xsl:when test='contains($value, $quot) and contains($value, $apos)'>
        <xsl:text>"</xsl:text>
        <xsl:call-template name='str:subst'>
          <xsl:with-param name='text' select='$value'/>
          <xsl:with-param name='replace'>"</xsl:with-param>
          <xsl:with-param name='with'>
            <xsl:text disable-output-escaping='yes'>&amp;quot;</xsl:text>
          </xsl:with-param>
        </xsl:call-template>
        <xsl:text>"</xsl:text>
      </xsl:when>
      <xsl:when test='contains($value, $quot)'>
        <xsl:text>'</xsl:text>
        <xsl:value-of select='$value'/>
        <xsl:text>'</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>"</xsl:text>
        <xsl:value-of select='$value'/>
        <xsl:text>"</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <doc:template name="markup:external-identifier" xmlns="">
    <refpurpose>Create an External Identifier</refpurpose>

    <refdescription>
      <para>This template returns an external identifier.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>publicid</term>
	  <listitem>
	    <para>The public identifier.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>systemid</term>
	  <listitem>
	    <para>The system identifier.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns an external identifier as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:external-identifier'>
    <xsl:param name='publicid'/>
    <xsl:param name='systemid'/>
    <xsl:param name='leading-space' select='false()'/>

    <xsl:choose>
      <xsl:when test='string-length($publicid) &gt; 0'>
        <xsl:if test='$leading-space'>
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:text disable-output-escaping='yes'>PUBLIC "</xsl:text>
        <xsl:value-of select='$publicid' disable-output-escaping='yes'/>
        <xsl:text disable-output-escaping='yes'>"</xsl:text>
        <xsl:if test='string-length($systemid) &gt; 0'>
          <xsl:text disable-output-escaping='yes'> "</xsl:text>
          <xsl:value-of select='$systemid' disable-output-escaping='yes'/>
          <xsl:text disable-output-escaping='yes'>"</xsl:text>
        </xsl:if>
      </xsl:when>
      <xsl:when test="string-length($systemid) &gt; 0">
        <xsl:if test='$leading-space'>
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:text disable-output-escaping='yes'>SYSTEM "</xsl:text>
        <xsl:value-of select='$systemid' disable-output-escaping='yes'/>
        <xsl:text disable-output-escaping='yes'>"</xsl:text>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <doc:template name="markup:entity-reference" xmlns="">
    <refpurpose>Create an Entity Reference</refpurpose>

    <refdescription>
      <para>This template returns an entity reference.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>name</term>
	  <listitem>
	    <para>The name of the entity.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns an entity reference as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:entity-reference'>
    <xsl:param name='name'/>

    <xsl:text disable-output-escaping='yes'>&amp;</xsl:text>
    <xsl:value-of select='$name'/>
    <xsl:text>;</xsl:text>

  </xsl:template>

  <doc:template name="markup:notation-declaration" xmlns="">
    <refpurpose>Create a Notation Declaration</refpurpose>

    <refdescription>
      <para>This template returns a notation declaration.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>name</term>
	  <listitem>
	    <para>The notation name.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>publicid</term>
	  <listitem>
	    <para>The public identifier for the notation.</para>
	  </listitem>
	</varlistentry>
	<varlistentry>
	  <term>systemid</term>
	  <listitem>
	    <para>The system identifier for the notation.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns a notation declaration as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:notation-declaration'>
    <xsl:param name='name'/>
    <xsl:param name='publicid'/>
    <xsl:param name='systemid'/>

    <xsl:if test='string-length($name) = 0'>
      <xsl:message terminate='yes'>notation name must be specified</xsl:message>
    </xsl:if>
    <xsl:if test='string-length($publicid) = 0 and string-length($systemid) = 0'>
      <xsl:message terminate='yes'>external identifier must be specified</xsl:message>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&lt;!NOTATION </xsl:text>
    <xsl:copy-of select='$name'/>

    <xsl:call-template name='markup:external-identifier'>
      <xsl:with-param name='publicid' select='$publicid'/>
      <xsl:with-param name='systemid' select='$systemid'/>
      <xsl:with-param name='leading-space' select='true()'/>
    </xsl:call-template>

    <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  </xsl:template>

  <doc:template name="markup:cdata-section" xmlns="">
    <refpurpose>Create a CDATA Section</refpurpose>

    <refdescription>
      <para>This template returns a CDATA Section.  The XSLT specification provides a mechanism for instructing the XSL processor to output character data in a CDATA section for certain elements, but this template may be useful in those circumstances where not all instances of an element are to have their content placed in a CDATA section.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>text</term>
	  <listitem>
	    <para>The content of the CDATA section.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns a CDATA section as a string.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:cdata-section'>
    <xsl:param name='text'/>

    <xsl:if test="contains($text, ']]&gt;')">
      <xsl:message terminate="yes">CDATA section contains "]]&gt;"</xsl:message>
    </xsl:if>

    <xsl:text disable-output-escaping='yes'>&lt;![CDATA[</xsl:text>
    <xsl:copy-of select='$text'/>
    <xsl:text disable-output-escaping='yes'>]]&gt;</xsl:text>
  </xsl:template>

  <doc:template name="markup:as-xml" xmlns="">
    <refpurpose>Format Nodeset As XML Markup</refpurpose>

    <refdescription>
      <para>This template returns XML markup.  Each node in the given nodeset is converted to its equivalent XML markup.</para>

      <para>BUG: This version may not adequately handle XML Namespaces.</para>
    </refdescription>

    <refparameter>
      <variablelist>
	<varlistentry>
	  <term>nodes</term>
	  <listitem>
	    <para>Nodeset to format as XML.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </refparameter>

    <refreturn>
      <para>Returns XML markup.</para>
    </refreturn>
  </doc:template>

  <xsl:template name='markup:as-xml'>
    <xsl:param name='nodes'/>

    <xsl:if test="$nodes">
      <xsl:choose>
        <xsl:when test="$nodes[1]/self::*">
          <xsl:text disable-output-escaping='yes'>&lt;</xsl:text>
          <xsl:value-of select="name($nodes[1])"/>
          <xsl:for-each select="$nodes[1]/@*">
            <xsl:text> </xsl:text>
            <xsl:value-of select="name()"/>
            <xsl:text>=</xsl:text>
            <xsl:call-template name='markup:quote-value'>
              <xsl:with-param name='value' select='.'/>
            </xsl:call-template>
          </xsl:for-each>

          <xsl:choose>
            <xsl:when test='$nodes[1]/node()'>
              <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
              <xsl:call-template name='markup:as-xml'>
                <xsl:with-param name='nodes' select='$nodes[1]/node()'/>
              </xsl:call-template>
              <xsl:text disable-output-escaping='yes'>&lt;/</xsl:text>
              <xsl:value-of select="name($nodes[1])"/>
              <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text disable-output-escaping='yes'>/&gt;</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:when test="$nodes[1]/self::text()">
          <xsl:value-of select="$nodes[1]"/>
        </xsl:when>
        <xsl:when test="$nodes[1]/self::comment()">
          <xsl:text disable-output-escaping='yes'>&lt;!--</xsl:text>
          <xsl:value-of select="$nodes[1]"/>
          <xsl:text disable-output-escaping='yes'>--&gt;</xsl:text>
        </xsl:when>
        <xsl:when test="$nodes[1]/self::processing-instruction()">
          <xsl:text disable-output-escaping='yes'>&lt;?</xsl:text>
          <xsl:value-of select="name($nodes[1])"/>
          <xsl:text> </xsl:text>
          <xsl:value-of select="$nodes[1]"/>
          <xsl:text disable-output-escaping='yes'>?&gt;</xsl:text>
        </xsl:when>

        <xsl:when test="not($nodes[1]/parent::*)"/> <!-- root node -->
        <xsl:when test="count($nodes[1] | $nodes[1]/../namespace::*) = count($nodes[1]/../namespace::*)"/> <!-- namespace node -->
        <xsl:when test="count($nodes[1] | $nodes[1]/../@*) = count($nodes[1]/../@*)"/> <!-- attribute node -->
      </xsl:choose>

      <xsl:call-template name="markup:as-xml">
        <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>