Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

markup.xsl 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <xsl:stylesheet version='1.0'
  2. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  3. xmlns:doc='http://xsltsl.org/xsl/documentation/1.0'
  4. xmlns:markup='http://xsltsl.org/markup'
  5. xmlns:str='http://xsltsl.org/string'
  6. extension-element-prefixes='doc markup str'>
  7. <doc:reference xmlns=''>
  8. <referenceinfo>
  9. <releaseinfo role="meta">
  10. $Id: markup.xsl,v 1.5 2003/03/31 21:07:28 balls Exp $
  11. </releaseinfo>
  12. <author>
  13. <surname>Ball</surname>
  14. <firstname>Steve</firstname>
  15. </author>
  16. <copyright>
  17. <year>2003</year>
  18. <year>2001</year>
  19. <holder>Steve Ball</holder>
  20. </copyright>
  21. </referenceinfo>
  22. <title>XML Markup Templates</title>
  23. <partintro>
  24. <section>
  25. <title>Introduction</title>
  26. <para>This stylesheet module provides functions for generating literal XML markup.</para>
  27. </section>
  28. </partintro>
  29. </doc:reference>
  30. <doc:template name="markup:xml-declaration" xmlns="">
  31. <refpurpose>Create an XML Declaration</refpurpose>
  32. <refdescription>
  33. <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>
  34. </refdescription>
  35. <refparameter>
  36. <variablelist>
  37. <varlistentry>
  38. <term>version</term>
  39. <listitem>
  40. <para>Version number.</para>
  41. </listitem>
  42. </varlistentry>
  43. <varlistentry>
  44. <term>standalone</term>
  45. <listitem>
  46. <para>Standalone indication. Must be value "yes" or "no".</para>
  47. </listitem>
  48. </varlistentry>
  49. <varlistentry>
  50. <term>encoding</term>
  51. <listitem>
  52. <para>Character encoding.</para>
  53. </listitem>
  54. </varlistentry>
  55. </variablelist>
  56. </refparameter>
  57. <refreturn>
  58. <para>Returns an XML Declaration as a string.</para>
  59. </refreturn>
  60. </doc:template>
  61. <xsl:template name='markup:xml-declaration'>
  62. <xsl:param name='version' select="'1.0'"/>
  63. <xsl:param name='standalone'/>
  64. <xsl:param name='encoding'/>
  65. <xsl:text disable-output-escaping='yes'>&lt;?xml version="</xsl:text>
  66. <xsl:copy-of select="$version"/>
  67. <xsl:text>"</xsl:text>
  68. <xsl:choose>
  69. <xsl:when test="string-length($standalone) = 0"/>
  70. <xsl:when test='$standalone = "yes" or $standalone = "no"'>
  71. <xsl:text> standalone="</xsl:text>
  72. <xsl:copy-of select="$standalone"/>
  73. <xsl:text>"</xsl:text>
  74. </xsl:when>
  75. <xsl:otherwise>
  76. <xsl:message terminate="yes">invalid value "<xsl:value-of select="$standalone"/>" for standalone attribute</xsl:message>
  77. </xsl:otherwise>
  78. </xsl:choose>
  79. <xsl:if test='string-length($encoding) &gt; 0'>
  80. <xsl:text> encoding="</xsl:text>
  81. <xsl:copy-of select='$encoding'/>
  82. <xsl:text>"</xsl:text>
  83. </xsl:if>
  84. <xsl:text disable-output-escaping='yes'>?&gt;
  85. </xsl:text>
  86. </xsl:template>
  87. <doc:template name="markup:doctype-declaration" xmlns="">
  88. <refpurpose>Create a Document Type Declaration</refpurpose>
  89. <refdescription>
  90. <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>
  91. </refdescription>
  92. <refparameter>
  93. <variablelist>
  94. <varlistentry>
  95. <term>docel</term>
  96. <listitem>
  97. <para>The name of the document element.</para>
  98. </listitem>
  99. </varlistentry>
  100. <varlistentry>
  101. <term>publicid</term>
  102. <listitem>
  103. <para>The public identifier for the external DTD subset.</para>
  104. </listitem>
  105. </varlistentry>
  106. <varlistentry>
  107. <term>systemid</term>
  108. <listitem>
  109. <para>The system identifier for the external DTD subset.</para>
  110. </listitem>
  111. </varlistentry>
  112. <varlistentry>
  113. <term>internaldtd</term>
  114. <listitem>
  115. <para>The internal DTD subset.</para>
  116. </listitem>
  117. </varlistentry>
  118. </variablelist>
  119. </refparameter>
  120. <refreturn>
  121. <para>Returns a Document Type Declaration as a string.</para>
  122. </refreturn>
  123. </doc:template>
  124. <xsl:template name='markup:doctype-declaration'>
  125. <xsl:param name='docel'/>
  126. <xsl:param name='publicid'/>
  127. <xsl:param name='systemid'/>
  128. <xsl:param name='internaldtd'/>
  129. <xsl:if test='string-length($docel) = 0'>
  130. <xsl:message terminate='yes'>No document element specified</xsl:message>
  131. </xsl:if>
  132. <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE </xsl:text>
  133. <xsl:copy-of select="$docel"/>
  134. <xsl:call-template name='markup:external-identifier'>
  135. <xsl:with-param name='publicid' select='$publicid'/>
  136. <xsl:with-param name='systemid' select='$systemid'/>
  137. <xsl:with-param name='leading-space' select='true()'/>
  138. </xsl:call-template>
  139. <xsl:if test='string-length($internaldtd) &gt; 0'>
  140. <xsl:text> [</xsl:text>
  141. <xsl:copy-of select='$internaldtd'/>
  142. <xsl:text>]</xsl:text>
  143. </xsl:if>
  144. <xsl:text disable-output-escaping='yes'>&gt;
  145. </xsl:text>
  146. </xsl:template>
  147. <doc:template name="markup:element-declaration" xmlns="">
  148. <refpurpose>Create an Element Declaration</refpurpose>
  149. <refdescription>
  150. <para>This template returns an element declaration..</para>
  151. </refdescription>
  152. <refparameter>
  153. <variablelist>
  154. <varlistentry>
  155. <term>type</term>
  156. <listitem>
  157. <para>The element type.</para>
  158. </listitem>
  159. </varlistentry>
  160. <varlistentry>
  161. <term>content-spec</term>
  162. <listitem>
  163. <para>The content specification.</para>
  164. </listitem>
  165. </varlistentry>
  166. </variablelist>
  167. </refparameter>
  168. <refreturn>
  169. <para>Returns an element declaration as a string.</para>
  170. </refreturn>
  171. </doc:template>
  172. <xsl:template name='markup:element-declaration'>
  173. <xsl:param name='type'/>
  174. <xsl:param name='content-spec' select="'ANY'"/>
  175. <xsl:if test='string-length($type) = 0'>
  176. <xsl:message terminate='yes'>element type must be specified</xsl:message>
  177. </xsl:if>
  178. <xsl:if test='string-length($content-spec) = 0'>
  179. <xsl:message terminate='yes'>content specification must be specified</xsl:message>
  180. </xsl:if>
  181. <xsl:text disable-output-escaping='yes'>&lt;!ELEMENT </xsl:text>
  182. <xsl:copy-of select='$type'/>
  183. <xsl:text> </xsl:text>
  184. <xsl:copy-of select='$content-spec'/>
  185. <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  186. </xsl:template>
  187. <doc:template name="markup:attlist-declaration" xmlns="">
  188. <refpurpose>Create an Attribute List Declaration</refpurpose>
  189. <refdescription>
  190. <para>This template returns an attribute list declaration.</para>
  191. </refdescription>
  192. <refparameter>
  193. <variablelist>
  194. <varlistentry>
  195. <term>type</term>
  196. <listitem>
  197. <para>The element type.</para>
  198. </listitem>
  199. </varlistentry>
  200. <varlistentry>
  201. <term>attr-defns</term>
  202. <listitem>
  203. <para>Attribute definitions.</para>
  204. </listitem>
  205. </varlistentry>
  206. </variablelist>
  207. </refparameter>
  208. <refreturn>
  209. <para>Returns an attribute list declaration as a string.</para>
  210. </refreturn>
  211. </doc:template>
  212. <xsl:template name='markup:attlist-declaration'>
  213. <xsl:param name='type'/>
  214. <xsl:param name='attr-defns'/>
  215. <xsl:if test='string-length($type) = 0'>
  216. <xsl:message terminate='yes'>element type must be specified</xsl:message>
  217. </xsl:if>
  218. <xsl:text disable-output-escaping='yes'>&lt;!ATTLIST </xsl:text>
  219. <xsl:copy-of select='$type'/>
  220. <xsl:text> </xsl:text>
  221. <xsl:copy-of select='$attr-defns'/>
  222. <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  223. </xsl:template>
  224. <doc:template name="markup:attribute-definition" xmlns="">
  225. <refpurpose>Create an Attribute Definition</refpurpose>
  226. <refdescription>
  227. <para>This template returns an attribute definition.</para>
  228. </refdescription>
  229. <refparameter>
  230. <variablelist>
  231. <varlistentry>
  232. <term>name</term>
  233. <listitem>
  234. <para>The attribute name.</para>
  235. </listitem>
  236. </varlistentry>
  237. <varlistentry>
  238. <term>type</term>
  239. <listitem>
  240. <para>The attribute type.</para>
  241. </listitem>
  242. </varlistentry>
  243. <varlistentry>
  244. <term>default</term>
  245. <listitem>
  246. <para>The attribute default.</para>
  247. </listitem>
  248. </varlistentry>
  249. </variablelist>
  250. </refparameter>
  251. <refreturn>
  252. <para>Returns an attribute definition as a string.</para>
  253. </refreturn>
  254. </doc:template>
  255. <xsl:template name='markup:attribute-definition'>
  256. <xsl:param name='name'/>
  257. <xsl:param name='type'/>
  258. <xsl:param name='default'/>
  259. <xsl:if test='string-length($name) = 0'>
  260. <xsl:message terminate='yes'>attribute name must be specified</xsl:message>
  261. </xsl:if>
  262. <xsl:if test='string-length($type) = 0'>
  263. <xsl:message terminate='yes'>attribute type must be specified</xsl:message>
  264. </xsl:if>
  265. <xsl:if test='string-length($default) = 0'>
  266. <xsl:message terminate='yes'>attribute default must be specified</xsl:message>
  267. </xsl:if>
  268. <xsl:text> </xsl:text>
  269. <xsl:copy-of select='$name'/>
  270. <xsl:text> </xsl:text>
  271. <xsl:copy-of select='$type'/>
  272. <xsl:text> </xsl:text>
  273. <xsl:copy-of select='$default'/>
  274. </xsl:template>
  275. <doc:template name="markup:entity-declaration" xmlns="">
  276. <refpurpose>Create an Entity Declaration</refpurpose>
  277. <refdescription>
  278. <para>This template returns an entity declaration.</para>
  279. <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>
  280. </refdescription>
  281. <refparameter>
  282. <variablelist>
  283. <varlistentry>
  284. <term>name</term>
  285. <listitem>
  286. <para>The entity name.</para>
  287. </listitem>
  288. </varlistentry>
  289. <varlistentry>
  290. <term>parameter</term>
  291. <listitem>
  292. <para>Boolean value to determine whether a parameter entity is created. Default is 'false()'.</para>
  293. </listitem>
  294. </varlistentry>
  295. <varlistentry>
  296. <term>text</term>
  297. <listitem>
  298. <para>The replacement text. Must be a string.</para>
  299. </listitem>
  300. </varlistentry>
  301. <varlistentry>
  302. <term>nodes</term>
  303. <listitem>
  304. <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>
  305. </listitem>
  306. </varlistentry>
  307. <varlistentry>
  308. <term>publicid</term>
  309. <listitem>
  310. <para>The public identifier for an external entity.</para>
  311. </listitem>
  312. </varlistentry>
  313. <varlistentry>
  314. <term>systemid</term>
  315. <listitem>
  316. <para>The system identifier for an external entity.</para>
  317. </listitem>
  318. </varlistentry>
  319. <varlistentry>
  320. <term>notation</term>
  321. <listitem>
  322. <para>The notation for an external entity.</para>
  323. </listitem>
  324. </varlistentry>
  325. </variablelist>
  326. </refparameter>
  327. <refreturn>
  328. <para>Returns an entity declaration as a string.</para>
  329. </refreturn>
  330. </doc:template>
  331. <xsl:template name='markup:entity-declaration'>
  332. <xsl:param name='name'/>
  333. <xsl:param name='parameter' select='false()'/>
  334. <xsl:param name='text'/>
  335. <xsl:param name='nodes'/>
  336. <xsl:param name='publicid'/>
  337. <xsl:param name='systemid'/>
  338. <xsl:param name='notation'/>
  339. <xsl:if test='string-length($name) = 0'>
  340. <xsl:message terminate='yes'>entity name must be specified</xsl:message>
  341. </xsl:if>
  342. <xsl:if test='string-length($text) &gt; 0 and
  343. (string-length($publicid) &gt; 0 or
  344. string-length($systemid) &gt; 0 or
  345. string-length($notation) &gt; 0)'>
  346. <xsl:message terminate='yes'>both replacement text and external identifier specified</xsl:message>
  347. </xsl:if>
  348. <xsl:text disable-output-escaping='yes'>&lt;!ENTITY </xsl:text>
  349. <xsl:copy-of select='$name'/>
  350. <xsl:text> </xsl:text>
  351. <xsl:if test="$parameter">
  352. <xsl:text>% </xsl:text>
  353. </xsl:if>
  354. <xsl:choose>
  355. <xsl:when test="$nodes">
  356. <xsl:call-template name='markup:quote-value'>
  357. <xsl:with-param name='value'>
  358. <xsl:call-template name="markup:as-xml">
  359. <xsl:with-param name="nodes" select="$nodes"/>
  360. </xsl:call-template>
  361. </xsl:with-param>
  362. </xsl:call-template>
  363. </xsl:when>
  364. <xsl:when test='$text'>
  365. <xsl:call-template name='markup:quote-value'>
  366. <xsl:with-param name='value' select='$text'/>
  367. </xsl:call-template>
  368. </xsl:when>
  369. <xsl:otherwise>
  370. <xsl:call-template name='markup:external-identifier'>
  371. <xsl:with-param name='publicid' select='$publicid'/>
  372. <xsl:with-param name='systemid' select='$systemid'/>
  373. </xsl:call-template>
  374. </xsl:otherwise>
  375. </xsl:choose>
  376. <xsl:if test='$notation'>
  377. <xsl:text> NDATA "</xsl:text>
  378. <xsl:copy-of select='$notation'/>
  379. <xsl:text>"</xsl:text>
  380. </xsl:if>
  381. <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  382. </xsl:template>
  383. <doc:template name="markup:quote-value" xmlns="">
  384. <refpurpose>Quote an Attribute Value</refpurpose>
  385. <refdescription>
  386. <para>This template returns a quoted value.</para>
  387. </refdescription>
  388. <refparameter>
  389. <variablelist>
  390. <varlistentry>
  391. <term>value</term>
  392. <listitem>
  393. <para>The value to quote.</para>
  394. </listitem>
  395. </varlistentry>
  396. </variablelist>
  397. </refparameter>
  398. <refreturn>
  399. <para>Returns a quote value as a string.</para>
  400. </refreturn>
  401. </doc:template>
  402. <xsl:template name='markup:quote-value'>
  403. <xsl:param name='value'/>
  404. <xsl:variable name="quoted">
  405. <xsl:call-template name='markup:quote-value-aux'>
  406. <xsl:with-param name='value' select='$value'/>
  407. </xsl:call-template>
  408. </xsl:variable>
  409. <xsl:choose>
  410. <xsl:when test="contains($value, '&lt;')">
  411. <xsl:call-template name='str:subst'>
  412. <xsl:with-param name='text' select='$quoted'/>
  413. <xsl:with-param name='replace'>&lt;</xsl:with-param>
  414. <xsl:with-param name='with'>
  415. <xsl:text disable-output-escaping='yes'>&amp;lt;</xsl:text>
  416. </xsl:with-param>
  417. </xsl:call-template>
  418. </xsl:when>
  419. <xsl:otherwise>
  420. <xsl:copy-of select='$quoted'/>
  421. </xsl:otherwise>
  422. </xsl:choose>
  423. </xsl:template>
  424. <xsl:template name='markup:quote-value-aux'>
  425. <xsl:param name='value'/>
  426. <!-- Quoting hell! -->
  427. <xsl:variable name="quot">&quot;</xsl:variable>
  428. <xsl:variable name="apos">&apos;</xsl:variable>
  429. <xsl:choose>
  430. <xsl:when test='contains($value, $quot) and contains($value, $apos)'>
  431. <xsl:text>"</xsl:text>
  432. <xsl:call-template name='str:subst'>
  433. <xsl:with-param name='text' select='$value'/>
  434. <xsl:with-param name='replace'>"</xsl:with-param>
  435. <xsl:with-param name='with'>
  436. <xsl:text disable-output-escaping='yes'>&amp;quot;</xsl:text>
  437. </xsl:with-param>
  438. </xsl:call-template>
  439. <xsl:text>"</xsl:text>
  440. </xsl:when>
  441. <xsl:when test='contains($value, $quot)'>
  442. <xsl:text>'</xsl:text>
  443. <xsl:value-of select='$value'/>
  444. <xsl:text>'</xsl:text>
  445. </xsl:when>
  446. <xsl:otherwise>
  447. <xsl:text>"</xsl:text>
  448. <xsl:value-of select='$value'/>
  449. <xsl:text>"</xsl:text>
  450. </xsl:otherwise>
  451. </xsl:choose>
  452. </xsl:template>
  453. <doc:template name="markup:external-identifier" xmlns="">
  454. <refpurpose>Create an External Identifier</refpurpose>
  455. <refdescription>
  456. <para>This template returns an external identifier.</para>
  457. </refdescription>
  458. <refparameter>
  459. <variablelist>
  460. <varlistentry>
  461. <term>publicid</term>
  462. <listitem>
  463. <para>The public identifier.</para>
  464. </listitem>
  465. </varlistentry>
  466. <varlistentry>
  467. <term>systemid</term>
  468. <listitem>
  469. <para>The system identifier.</para>
  470. </listitem>
  471. </varlistentry>
  472. </variablelist>
  473. </refparameter>
  474. <refreturn>
  475. <para>Returns an external identifier as a string.</para>
  476. </refreturn>
  477. </doc:template>
  478. <xsl:template name='markup:external-identifier'>
  479. <xsl:param name='publicid'/>
  480. <xsl:param name='systemid'/>
  481. <xsl:param name='leading-space' select='false()'/>
  482. <xsl:choose>
  483. <xsl:when test='string-length($publicid) &gt; 0'>
  484. <xsl:if test='$leading-space'>
  485. <xsl:text> </xsl:text>
  486. </xsl:if>
  487. <xsl:text disable-output-escaping='yes'>PUBLIC "</xsl:text>
  488. <xsl:value-of select='$publicid' disable-output-escaping='yes'/>
  489. <xsl:text disable-output-escaping='yes'>"</xsl:text>
  490. <xsl:if test='string-length($systemid) &gt; 0'>
  491. <xsl:text disable-output-escaping='yes'> "</xsl:text>
  492. <xsl:value-of select='$systemid' disable-output-escaping='yes'/>
  493. <xsl:text disable-output-escaping='yes'>"</xsl:text>
  494. </xsl:if>
  495. </xsl:when>
  496. <xsl:when test="string-length($systemid) &gt; 0">
  497. <xsl:if test='$leading-space'>
  498. <xsl:text> </xsl:text>
  499. </xsl:if>
  500. <xsl:text disable-output-escaping='yes'>SYSTEM "</xsl:text>
  501. <xsl:value-of select='$systemid' disable-output-escaping='yes'/>
  502. <xsl:text disable-output-escaping='yes'>"</xsl:text>
  503. </xsl:when>
  504. </xsl:choose>
  505. </xsl:template>
  506. <doc:template name="markup:entity-reference" xmlns="">
  507. <refpurpose>Create an Entity Reference</refpurpose>
  508. <refdescription>
  509. <para>This template returns an entity reference.</para>
  510. </refdescription>
  511. <refparameter>
  512. <variablelist>
  513. <varlistentry>
  514. <term>name</term>
  515. <listitem>
  516. <para>The name of the entity.</para>
  517. </listitem>
  518. </varlistentry>
  519. </variablelist>
  520. </refparameter>
  521. <refreturn>
  522. <para>Returns an entity reference as a string.</para>
  523. </refreturn>
  524. </doc:template>
  525. <xsl:template name='markup:entity-reference'>
  526. <xsl:param name='name'/>
  527. <xsl:text disable-output-escaping='yes'>&amp;</xsl:text>
  528. <xsl:value-of select='$name'/>
  529. <xsl:text>;</xsl:text>
  530. </xsl:template>
  531. <doc:template name="markup:notation-declaration" xmlns="">
  532. <refpurpose>Create a Notation Declaration</refpurpose>
  533. <refdescription>
  534. <para>This template returns a notation declaration.</para>
  535. </refdescription>
  536. <refparameter>
  537. <variablelist>
  538. <varlistentry>
  539. <term>name</term>
  540. <listitem>
  541. <para>The notation name.</para>
  542. </listitem>
  543. </varlistentry>
  544. <varlistentry>
  545. <term>publicid</term>
  546. <listitem>
  547. <para>The public identifier for the notation.</para>
  548. </listitem>
  549. </varlistentry>
  550. <varlistentry>
  551. <term>systemid</term>
  552. <listitem>
  553. <para>The system identifier for the notation.</para>
  554. </listitem>
  555. </varlistentry>
  556. </variablelist>
  557. </refparameter>
  558. <refreturn>
  559. <para>Returns a notation declaration as a string.</para>
  560. </refreturn>
  561. </doc:template>
  562. <xsl:template name='markup:notation-declaration'>
  563. <xsl:param name='name'/>
  564. <xsl:param name='publicid'/>
  565. <xsl:param name='systemid'/>
  566. <xsl:if test='string-length($name) = 0'>
  567. <xsl:message terminate='yes'>notation name must be specified</xsl:message>
  568. </xsl:if>
  569. <xsl:if test='string-length($publicid) = 0 and string-length($systemid) = 0'>
  570. <xsl:message terminate='yes'>external identifier must be specified</xsl:message>
  571. </xsl:if>
  572. <xsl:text disable-output-escaping='yes'>&lt;!NOTATION </xsl:text>
  573. <xsl:copy-of select='$name'/>
  574. <xsl:call-template name='markup:external-identifier'>
  575. <xsl:with-param name='publicid' select='$publicid'/>
  576. <xsl:with-param name='systemid' select='$systemid'/>
  577. <xsl:with-param name='leading-space' select='true()'/>
  578. </xsl:call-template>
  579. <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  580. </xsl:template>
  581. <doc:template name="markup:cdata-section" xmlns="">
  582. <refpurpose>Create a CDATA Section</refpurpose>
  583. <refdescription>
  584. <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>
  585. </refdescription>
  586. <refparameter>
  587. <variablelist>
  588. <varlistentry>
  589. <term>text</term>
  590. <listitem>
  591. <para>The content of the CDATA section.</para>
  592. </listitem>
  593. </varlistentry>
  594. </variablelist>
  595. </refparameter>
  596. <refreturn>
  597. <para>Returns a CDATA section as a string.</para>
  598. </refreturn>
  599. </doc:template>
  600. <xsl:template name='markup:cdata-section'>
  601. <xsl:param name='text'/>
  602. <xsl:if test="contains($text, ']]&gt;')">
  603. <xsl:message terminate="yes">CDATA section contains "]]&gt;"</xsl:message>
  604. </xsl:if>
  605. <xsl:text disable-output-escaping='yes'>&lt;![CDATA[</xsl:text>
  606. <xsl:copy-of select='$text'/>
  607. <xsl:text disable-output-escaping='yes'>]]&gt;</xsl:text>
  608. </xsl:template>
  609. <doc:template name="markup:as-xml" xmlns="">
  610. <refpurpose>Format Nodeset As XML Markup</refpurpose>
  611. <refdescription>
  612. <para>This template returns XML markup. Each node in the given nodeset is converted to its equivalent XML markup.</para>
  613. <para>BUG: This version may not adequately handle XML Namespaces.</para>
  614. </refdescription>
  615. <refparameter>
  616. <variablelist>
  617. <varlistentry>
  618. <term>nodes</term>
  619. <listitem>
  620. <para>Nodeset to format as XML.</para>
  621. </listitem>
  622. </varlistentry>
  623. </variablelist>
  624. </refparameter>
  625. <refreturn>
  626. <para>Returns XML markup.</para>
  627. </refreturn>
  628. </doc:template>
  629. <xsl:template name='markup:as-xml'>
  630. <xsl:param name='nodes'/>
  631. <xsl:if test="$nodes">
  632. <xsl:choose>
  633. <xsl:when test="$nodes[1]/self::*">
  634. <xsl:text disable-output-escaping='yes'>&lt;</xsl:text>
  635. <xsl:value-of select="name($nodes[1])"/>
  636. <xsl:for-each select="$nodes[1]/@*">
  637. <xsl:text> </xsl:text>
  638. <xsl:value-of select="name()"/>
  639. <xsl:text>=</xsl:text>
  640. <xsl:call-template name='markup:quote-value'>
  641. <xsl:with-param name='value' select='.'/>
  642. </xsl:call-template>
  643. </xsl:for-each>
  644. <xsl:choose>
  645. <xsl:when test='$nodes[1]/node()'>
  646. <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  647. <xsl:call-template name='markup:as-xml'>
  648. <xsl:with-param name='nodes' select='$nodes[1]/node()'/>
  649. </xsl:call-template>
  650. <xsl:text disable-output-escaping='yes'>&lt;/</xsl:text>
  651. <xsl:value-of select="name($nodes[1])"/>
  652. <xsl:text disable-output-escaping='yes'>&gt;</xsl:text>
  653. </xsl:when>
  654. <xsl:otherwise>
  655. <xsl:text disable-output-escaping='yes'>/&gt;</xsl:text>
  656. </xsl:otherwise>
  657. </xsl:choose>
  658. </xsl:when>
  659. <xsl:when test="$nodes[1]/self::text()">
  660. <xsl:value-of select="$nodes[1]"/>
  661. </xsl:when>
  662. <xsl:when test="$nodes[1]/self::comment()">
  663. <xsl:text disable-output-escaping='yes'>&lt;!--</xsl:text>
  664. <xsl:value-of select="$nodes[1]"/>
  665. <xsl:text disable-output-escaping='yes'>--&gt;</xsl:text>
  666. </xsl:when>
  667. <xsl:when test="$nodes[1]/self::processing-instruction()">
  668. <xsl:text disable-output-escaping='yes'>&lt;?</xsl:text>
  669. <xsl:value-of select="name($nodes[1])"/>
  670. <xsl:text> </xsl:text>
  671. <xsl:value-of select="$nodes[1]"/>
  672. <xsl:text disable-output-escaping='yes'>?&gt;</xsl:text>
  673. </xsl:when>
  674. <xsl:when test="not($nodes[1]/parent::*)"/> <!-- root node -->
  675. <xsl:when test="count($nodes[1] | $nodes[1]/../namespace::*) = count($nodes[1]/../namespace::*)"/> <!-- namespace node -->
  676. <xsl:when test="count($nodes[1] | $nodes[1]/../@*) = count($nodes[1]/../@*)"/> <!-- attribute node -->
  677. </xsl:choose>
  678. <xsl:call-template name="markup:as-xml">
  679. <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
  680. </xsl:call-template>
  681. </xsl:if>
  682. </xsl:template>
  683. </xsl:stylesheet>