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.

1159 lines
39 KiB

4 years ago
  1. <?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
  2. <!--
  3. OVERVIEW : iso_dsdl_include.xsl
  4. This is an inclusion preprocessor for the non-smart text inclusions
  5. of ISO DSDL. It handles
  6. <relax:extRef> for ISO RELAX NG
  7. <sch:include> for ISO Schematron and Schematron 1.n
  8. <sch:extends> for 2009 draft ISO Schematron
  9. <xi:xinclude> simple W3C XIncludes for ISO NVRL and DSRL
  10. <crdl:ref> for draft ISO CRDL
  11. <dtll:include> for draft ISO DTLL
  12. <* @xlink:href> for simple W3C XLink 1.1 embedded links
  13. This should be the first in any chain of processing. It only requires
  14. XSLT 1. Each kind of inclusion can be turned off (or on) on the command line.
  15. Ids in fragment identifiers or xpointers will be sought in the following
  16. order:
  17. * @xml:id
  18. * id() for typed schemas (e.g. from DTD) [NOTE: XInclude does not support this]
  19. * untyped @id
  20. The proposed behaviour for the update to ISO Schematron has been implemented. If an
  21. include points to an element with the same name as the parent, then that element's
  22. contents will be included. This supports the merge style of inclusion.
  23. When an inclusion is made, it is preceded by a PI with target DSDL_INCLUDE_START
  24. and the href and closed by a PI with target DSDL_INCLUDE_START and the href. This is
  25. to allow better location of problems, though only to the file level.
  26. Limitations:
  27. * No rebasing: relative paths will be interpreted based on the initial document's
  28. path, not the including document. (Severe limitation!)
  29. * No checking for circular references
  30. * Not full xpointers: only ID matching
  31. * <relax:include> not implemented
  32. * XInclude handling of xml:base and xml:lang not implemented
  33. -->
  34. <!--
  35. VERSION INFORMATION
  36. 2009-02-25
  37. * Update DSDL namespace to use schematron.com
  38. * Tested with SAXON9, Xalan 2.7.1, IE7,
  39. * IE does not like multiple variables in same template with same name: rename.
  40. 2008-09-18
  41. * Remove new behaviour for include, because it conflicts with existing usage [KH]
  42. * Add extends[@href] element with that merge functionality
  43. * Generate PIs to notate source of inclusions for potential better diagnostics
  44. 2008-09-16
  45. * Fix for XSLT1
  46. 2008-08-28
  47. * New behaviour for schematron includes: if the pointed to element is the same as the current,
  48. include the children.
  49. 2008-08-20
  50. * Fix bug: in XSLT1 cannot do $document/id('x') but need to use for-each
  51. 2008-08-04
  52. * Add support for inclusions in old namespace
  53. 2008-08-03
  54. * Fix wrong param name include-relaxng & include-crdl (KH, PH)
  55. * Allow inclusion of XSLT and XHTML (KH)
  56. * Fix inclusion of fragments (KH)
  57. 2008-07-25
  58. * Add selectable input parameter
  59. 2008-07-24
  60. * RJ New
  61. -->
  62. <!--
  63. LEGAL INFORMATION
  64. Copyright (c) 2008 Rick Jelliffe
  65. This software is provided 'as-is', without any express or implied warranty.
  66. In no event will the authors be held liable for any damages arising from
  67. the use of this software.
  68. Permission is granted to anyone to use this software for any purpose,
  69. including commercial applications, and to alter it and redistribute it freely,
  70. subject to the following restrictions:
  71. 1. The origin of this software must not be misrepresented; you must not claim
  72. that you wrote the original software. If you use this software in a product,
  73. an acknowledgment in the product documentation would be appreciated but is
  74. not required.
  75. 2. Altered source versions must be plainly marked as such, and must not be
  76. misrepresented as being the original software.
  77. 3. This notice may not be removed or altered from any source distribution.
  78. -->
  79. <xslt:stylesheet version="1.0"
  80. xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
  81. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  82. xmlns:iso="http://purl.oclc.org/dsdl/schematron"
  83. xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
  84. xmlns:xhtml="http://www.w3.org/1999/xhtml"
  85. xmlns:schold="http://www.ascc.net/xml/schematron"
  86. xmlns:crdl="http://purl.oclc.org/dsdl/crepdl/ns/structure/1.0"
  87. xmlns:xi="http://www.w3.org/2001/XInclude"
  88. xmlns:dtll="http://www.jenitennison.com/datatypes"
  89. xmlns:dsdl="http://www.schematron.com/namespace/dsdl"
  90. xmlns:relax="http://relaxng.org/ns/structure/1.0"
  91. xmlns:xlink="http://www.w3.org/1999/xlink">
  92. <!-- Note: The URL for the dsdl namespace is not official -->
  93. <xsl:param name="include-schematron">true</xsl:param>
  94. <xsl:param name="include-crdl">true</xsl:param>
  95. <xsl:param name="include-xinclude">true</xsl:param>
  96. <xsl:param name="include-dtll">true</xsl:param>
  97. <xsl:param name="include-relaxng">true</xsl:param>
  98. <xsl:param name="include-xlink">true</xsl:param>
  99. <xsl:template match="/">
  100. <xsl:apply-templates select="." mode="dsdl:go" />
  101. </xsl:template>
  102. <!-- output everything else unchanged -->
  103. <xslt:template match="node()" priority="-1" mode="dsdl:go">
  104. <xslt:copy>
  105. <xslt:copy-of select="@*" />
  106. <xslt:apply-templates mode="dsdl:go" />
  107. </xslt:copy>
  108. </xslt:template>
  109. <!-- =========================================================== -->
  110. <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
  111. <!-- Part 2 - Regular grammar-based validation - RELAX NG -->
  112. <!-- This only implements relax:extRef not relax:include which -->
  113. <!-- is complex. -->
  114. <!-- =========================================================== -->
  115. <xslt:template match="relax:extRef" mode="dsdl:go">
  116. <!-- Insert subschema -->
  117. <xsl:variable name="document-uri"
  118. select="substring-before(concat(@href,'#'), '#')" />
  119. <xsl:variable name="fragment-id"
  120. select="substring-after(@href, '#')" />
  121. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  122. <xsl:value-of select="@href" />
  123. </xsl:processing-instruction>
  124. <xsl:choose>
  125. <xsl:when test="not( $include-relaxng = 'true' )">
  126. <xslt:copy>
  127. <xslt:copy-of select="@*" />
  128. <xslt:apply-templates mode="dsdl:go" />
  129. </xslt:copy>
  130. </xsl:when>
  131. <xsl:otherwise>
  132. <xsl:choose>
  133. <xsl:when
  134. test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
  135. <xsl:message>
  136. Error: Impossible URL in RELAX NG extRef
  137. include
  138. </xsl:message>
  139. </xsl:when>
  140. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  141. <xslt:when
  142. test="string-length( $document-uri ) = 0">
  143. <xslt:apply-templates mode="dsdl:go"
  144. select="//*[@xml:id= $fragment-id ] | id( $fragment-id) | //*[@id= $fragment-id ]" />
  145. </xslt:when>
  146. <xsl:when
  147. test="string-length( $fragment-id ) &gt; 0">
  148. <xsl:variable name="theDocument_1"
  149. select="document( $document-uri,/ )" />
  150. <xsl:if test="not($theDocument_1)">
  151. <xsl:message terminate="no">
  152. <xsl:text>Unable to open referenced included file: </xsl:text>
  153. <xsl:value-of select="@href" />
  154. </xsl:message>
  155. </xsl:if>
  156. <!-- use a for-each so that the id() function works correctly on the external document -->
  157. <xsl:for-each select="$theDocument_1">
  158. <xsl:variable name="theFragment_1"
  159. select="$theDocument_1//*[@xml:id= $fragment-id ]
  160. | id( $fragment-id)
  161. | $theDocument_1//*[@id= $fragment-id ]" />
  162. <xsl:if test="not($theFragment_1)">
  163. <xsl:message terminate="no">
  164. <xsl:text>Unable to locate id attribute: </xsl:text>
  165. <xsl:value-of select="@href" />
  166. </xsl:message>
  167. </xsl:if>
  168. <xsl:apply-templates
  169. select=" $theFragment_1[1]" mode="dsdl:go" />
  170. </xsl:for-each>
  171. </xsl:when>
  172. <xsl:otherwise>
  173. <xsl:variable name="theDocument_2"
  174. select="document( $document-uri,/ )" />
  175. <xsl:variable name="theFragment_2"
  176. select="$theDocument_2/*" />
  177. <xsl:if test="not($theDocument_2)">
  178. <xsl:message terminate="no">
  179. <xsl:text>Unable to open referenced included file: </xsl:text>
  180. <xsl:value-of select="@href" />
  181. </xsl:message>
  182. </xsl:if>
  183. <xsl:if test="not($theFragment_2)">
  184. <xsl:message terminate="no">
  185. <xsl:text>Unable to locate id attribute: </xsl:text>
  186. <xsl:value-of select="@href" />
  187. </xsl:message>
  188. </xsl:if>
  189. <xsl:apply-templates select="$theFragment_2 "
  190. mode="dsdl:go" />
  191. </xsl:otherwise>
  192. </xsl:choose>
  193. </xsl:otherwise>
  194. </xsl:choose>
  195. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  196. <xsl:value-of select="@href" />
  197. </xsl:processing-instruction>
  198. </xslt:template>
  199. <!-- =========================================================== -->
  200. <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
  201. <!-- Part 3 - Rule-based validation - Schematron -->
  202. <!-- =========================================================== -->
  203. <!-- Extend the URI syntax to allow # references -->
  204. <!-- Add experimental support for simple containers like /xxx:xxx/iso:pattern to allow better includes -->
  205. <xsl:template match="iso:include" mode="dsdl:go">
  206. <xsl:variable name="document-uri"
  207. select="substring-before(concat(@href,'#'), '#')" />
  208. <xsl:variable name="fragment-id"
  209. select="substring-after(@href, '#')" />
  210. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  211. <xsl:value-of select="@href" />
  212. </xsl:processing-instruction>
  213. <xsl:choose>
  214. <xsl:when test="not( $include-schematron = 'true' )">
  215. <xslt:copy>
  216. <xslt:copy-of select="@*" />
  217. <xslt:apply-templates mode="dsdl:go" />
  218. </xslt:copy>
  219. </xsl:when>
  220. <xsl:otherwise>
  221. <xsl:choose>
  222. <xsl:when
  223. test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
  224. <xsl:message>
  225. Error: Impossible URL in Schematron include
  226. </xsl:message>
  227. </xsl:when>
  228. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  229. <xslt:when
  230. test="string-length( $document-uri ) = 0">
  231. <xslt:apply-templates mode="dsdl:go"
  232. select="//iso:*[@xml:id= $fragment-id ]
  233. |id( $fragment-id)
  234. | //iso:*[@id= $fragment-id ]" />
  235. </xslt:when>
  236. <!-- case where there is a fragment in another document (should be an iso: element) -->
  237. <!-- There are three cases for includes with fragment:
  238. 0) No href file or no matching id - error!
  239. 1) REMOVED
  240. 2) The linked-to element is sch:schema however the parent of the include
  241. is not a schema. In this case, it is an error. (Actually, it should
  242. be an error for other kinds of containment problems, but we won't
  243. check for them in this version.)
  244. 3) Otherwise, include the pointed-to element
  245. -->
  246. <xsl:when
  247. test="string-length( $fragment-id ) &gt; 0">
  248. <xsl:variable name="theDocument_1"
  249. select="document( $document-uri,/ )" />
  250. <xsl:variable name="originalParent" select=".." />
  251. <!-- case 0 -->
  252. <xsl:if test="not($theDocument_1)">
  253. <xsl:message terminate="no">
  254. <xsl:text>Unable to open referenced included file: </xsl:text>
  255. <xsl:value-of select="@href" />
  256. </xsl:message>
  257. </xsl:if>
  258. <!-- use for-each to rebase id() to external document -->
  259. <xsl:for-each select="$theDocument_1">
  260. <xsl:variable name="theFragment_1"
  261. select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
  262. id($fragment-id) |
  263. $theDocument_1//iso:*[@id= $fragment-id ]" />
  264. <xsl:choose>
  265. <!-- case 0 -->
  266. <xsl:when test="not($theFragment_1)">
  267. <xsl:message terminate="no">
  268. <xsl:text>Unable to locate id attribute: </xsl:text>
  269. <xsl:value-of select="@href" />
  270. </xsl:message>
  271. </xsl:when>
  272. <!-- case 1 REMOVED -->
  273. <!-- case 2 -->
  274. <xsl:when
  275. test=" $theFragment_1/self::iso:schema ">
  276. <xsl:message>
  277. Schema error: Use include to
  278. include fragments, not a whole
  279. schema
  280. </xsl:message>
  281. </xsl:when>
  282. <!-- case 3 -->
  283. <xsl:otherwise>
  284. <xsl:apply-templates
  285. select=" $theFragment_1[1]" mode="dsdl:go" />
  286. </xsl:otherwise>
  287. </xsl:choose>
  288. </xsl:for-each>
  289. </xsl:when>
  290. <!-- Case where there is no ID so we include the whole document -->
  291. <!-- Experimental addition: include fragments of children -->
  292. <xsl:otherwise>
  293. <xsl:variable name="theDocument_2"
  294. select="document( $document-uri,/ )" />
  295. <xsl:variable name="theFragment_2"
  296. select="$theDocument_2/iso:*" />
  297. <xsl:variable name="theContainedFragments"
  298. select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
  299. <xsl:if test="not($theDocument_2)">
  300. <xsl:message terminate="no">
  301. <xsl:text>Unable to open referenced included file: </xsl:text>
  302. <xsl:value-of select="@href" />
  303. </xsl:message>
  304. </xsl:if>
  305. <!-- There are three cases for includes:
  306. 0) No text specified- error!
  307. 1) REMOVED
  308. 2) The linked-to element is sch:schema however the parent of the include
  309. is not a schema. In this case, it is an error. (Actually, it should
  310. be an error for other kinds of containment problems, but we won't
  311. check for them in this version.)
  312. 3) Otherwise, include the pointed-to element
  313. -->
  314. <xsl:choose>
  315. <!-- case 0 -->
  316. <xsl:when
  317. test="not($theFragment_2) and not ($theContainedFragments)">
  318. <xsl:message terminate="no">
  319. <xsl:text>Unable to locate id attribute: </xsl:text>
  320. <xsl:value-of select="@href" />
  321. </xsl:message>
  322. </xsl:when>
  323. <!-- case 1 removed -->
  324. <!-- case 2 -->
  325. <xsl:when
  326. test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
  327. <xsl:message>
  328. Schema error: Use include to include
  329. fragments, not a whole schema
  330. </xsl:message>
  331. </xsl:when>
  332. <!-- If this were XLST 2, we could use
  333. if ($theFragment) then $theFragment else $theContainedFragments
  334. here (thanks to KN)
  335. -->
  336. <!-- case 3 -->
  337. <xsl:otherwise>
  338. <xsl:apply-templates
  339. select="$theFragment_2 " mode="dsdl:go" />
  340. </xsl:otherwise>
  341. </xsl:choose>
  342. </xsl:otherwise>
  343. </xsl:choose>
  344. </xsl:otherwise>
  345. </xsl:choose>
  346. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  347. <xsl:value-of select="@href" />
  348. </xsl:processing-instruction>
  349. </xsl:template>
  350. <!-- WARNING sch:extends[@href] is experimental and non standard -->
  351. <!-- Basically, it adds the children of the selected element, not the element itself. -->
  352. <xsl:template match="iso:extends[@href]" mode="dsdl:go">
  353. <xsl:variable name="document-uri"
  354. select="substring-before(concat(@href,'#'), '#')" />
  355. <xsl:variable name="fragment-id"
  356. select="substring-after(@href, '#')" />
  357. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  358. <xsl:value-of select="@href" />
  359. </xsl:processing-instruction>
  360. <xsl:choose>
  361. <xsl:when test="not( $include-schematron = 'true' )">
  362. <xslt:copy>
  363. <xslt:copy-of select="@*" />
  364. <xslt:apply-templates mode="dsdl:go" />
  365. </xslt:copy>
  366. </xsl:when>
  367. <xsl:otherwise>
  368. <xsl:choose>
  369. <xsl:when
  370. test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
  371. <xsl:message>
  372. Error: Impossible URL in Schematron include
  373. </xsl:message>
  374. </xsl:when>
  375. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  376. <xslt:when
  377. test="string-length( $document-uri ) = 0">
  378. <xslt:apply-templates mode="dsdl:go"
  379. select="//iso:*[@xml:id= $fragment-id ]/*
  380. |id( $fragment-id)/*
  381. | //iso:*[@id= $fragment-id ]/*" />
  382. </xslt:when>
  383. <!-- case where there is a fragment in another document (should be an iso: element) -->
  384. <!-- There are three cases for includes with fragment:
  385. 0) No href file or no matching id - error!
  386. 1) REMOVED
  387. 2) REMOVED
  388. 3) Otherwise, include the pointed-to element
  389. -->
  390. <xsl:when
  391. test="string-length( $fragment-id ) &gt; 0">
  392. <xsl:variable name="theDocument_1"
  393. select="document( $document-uri,/ )" />
  394. <xsl:variable name="originalParent" select=".." />
  395. <!-- case 0 -->
  396. <xsl:if test="not($theDocument_1)">
  397. <xsl:message terminate="no">
  398. <xsl:text>Unable to open referenced included file: </xsl:text>
  399. <xsl:value-of select="@href" />
  400. </xsl:message>
  401. </xsl:if>
  402. <!-- use for-each to rebase id() to external document -->
  403. <xsl:for-each select="$theDocument_1">
  404. <xsl:variable name="theFragment_1"
  405. select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
  406. id($fragment-id) |
  407. $theDocument_1//iso:*[@id= $fragment-id ]" />
  408. <xsl:choose>
  409. <!-- case 0 -->
  410. <xsl:when test="not($theFragment_1)">
  411. <xsl:message terminate="no">
  412. <xsl:text>Unable to locate id attribute: </xsl:text>
  413. <xsl:value-of select="@href" />
  414. </xsl:message>
  415. </xsl:when>
  416. <!-- case 1 REMOVED -->
  417. <!-- case 2 REMOVED -->
  418. <!-- case 3 -->
  419. <xsl:otherwise>
  420. <xsl:apply-templates
  421. select=" $theFragment_1[1]/*" mode="dsdl:go" />
  422. </xsl:otherwise>
  423. </xsl:choose>
  424. </xsl:for-each>
  425. </xsl:when>
  426. <!-- Case where there is no ID so we include the whole document -->
  427. <!-- Experimental addition: include fragments of children -->
  428. <xsl:otherwise>
  429. <xsl:variable name="theDocument_2"
  430. select="document( $document-uri,/ )" />
  431. <xsl:variable name="theFragment_2"
  432. select="$theDocument_2/iso:*" />
  433. <xsl:variable name="theContainedFragments"
  434. select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
  435. <xsl:if test="not($theDocument_2)">
  436. <xsl:message terminate="no">
  437. <xsl:text>Unable to open referenced included file: </xsl:text>
  438. <xsl:value-of select="@href" />
  439. </xsl:message>
  440. </xsl:if>
  441. <!-- There are three cases for includes:
  442. 0) No text specified- error!
  443. 1) REMOVED
  444. 2) REMOVED
  445. 3) Otherwise, include the pointed-to element
  446. -->
  447. <xsl:choose>
  448. <!-- case 0 -->
  449. <xsl:when
  450. test="not($theFragment_2) and not ($theContainedFragments)">
  451. <xsl:message terminate="no">
  452. <xsl:text>Unable to locate id attribute: </xsl:text>
  453. <xsl:value-of select="@href" />
  454. </xsl:message>
  455. </xsl:when>
  456. <!-- case 1 removed -->
  457. <!-- case 2 removed -->
  458. <!-- If this were XLST 2, we could use
  459. if ($theFragment) then $theFragment else $theContainedFragments
  460. here (thanks to KN)
  461. -->
  462. <!-- case 3 -->
  463. <xsl:otherwise>
  464. <xsl:apply-templates
  465. select="$theFragment_2/* " mode="dsdl:go" />
  466. </xsl:otherwise>
  467. </xsl:choose>
  468. </xsl:otherwise>
  469. </xsl:choose>
  470. </xsl:otherwise>
  471. </xsl:choose>
  472. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  473. <xsl:value-of select="@href" />
  474. </xsl:processing-instruction>
  475. </xsl:template>
  476. <!-- =========================================================== -->
  477. <!-- Handle Schematron 1.6 inclusions: clone of ISO code above -->
  478. <!-- =========================================================== -->
  479. <!-- Extend the URI syntax to allow # references -->
  480. <!-- Add experimental support for simple containers like /xxx:xxx/schold:pattern to allow better includes -->
  481. <xsl:template match="schold:include" mode="dsdl:go">
  482. <xsl:variable name="document-uri"
  483. select="substring-before(concat(@href,'#'), '#')" />
  484. <xsl:variable name="fragment-id"
  485. select="substring-after(@href, '#')" />
  486. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  487. <xsl:value-of select="@href" />
  488. </xsl:processing-instruction>
  489. <xsl:choose>
  490. <xsl:when test="not( $include-schematron = 'true' )">
  491. <xslt:copy>
  492. <xslt:copy-of select="@*" />
  493. <xslt:apply-templates mode="dsdl:go" />
  494. </xslt:copy>
  495. </xsl:when>
  496. <xsl:otherwise>
  497. <xsl:choose>
  498. <xsl:when
  499. test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
  500. <xsl:message>
  501. Error: Impossible URL in Schematron include
  502. </xsl:message>
  503. </xsl:when>
  504. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  505. <xslt:when
  506. test="string-length( $document-uri ) = 0">
  507. <xslt:apply-templates mode="dsdl:go"
  508. select="//schold:*[@xml:id= $fragment-id ]
  509. |id( $fragment-id)
  510. | //schold:*[@id= $fragment-id ]" />
  511. </xslt:when>
  512. <!-- case where there is a fragment in another document (should be an iso: element) -->
  513. <xsl:when
  514. test="string-length( $fragment-id ) &gt; 0">
  515. <xsl:variable name="theDocument_1"
  516. select="document( $document-uri,/ )" />
  517. <xsl:if test="not($theDocument_1)">
  518. <xsl:message terminate="no">
  519. <xsl:text>Unable to open referenced included file: </xsl:text>
  520. <xsl:value-of select="@href" />
  521. </xsl:message>
  522. </xsl:if>
  523. <!-- use for-each to rebase id() to $theDocument -->
  524. <xsl:for-each select="$theDocument_1">
  525. <xsl:variable name="theFragment_1"
  526. select=" $theDocument_1//schold:*[@xml:id= $fragment-id ] |
  527. id($fragment-id) |
  528. $theDocument_1//schold:*[@id= $fragment-id ]" />
  529. <xsl:if
  530. test=" $theFragment_1/self::schold:schema ">
  531. <xsl:message>
  532. Schema error: Use include to include
  533. fragments, not a whole schema
  534. </xsl:message>
  535. </xsl:if>
  536. <xsl:if test="not($theFragment_1)">
  537. <xsl:message terminate="no">
  538. <xsl:text>Unable to locate id attribute: </xsl:text>
  539. <xsl:value-of select="@href" />
  540. </xsl:message>
  541. </xsl:if>
  542. <xsl:apply-templates
  543. select=" $theFragment_1[1]" mode="dsdl:go" />
  544. </xsl:for-each>
  545. </xsl:when>
  546. <!-- Case where there is no ID so we include the whole document -->
  547. <!-- Experimental addition: include fragments of children -->
  548. <xsl:otherwise>
  549. <xsl:variable name="theDocument_2"
  550. select="document( $document-uri,/ )" />
  551. <xsl:variable name="theFragment_2"
  552. select="$theDocument_2/iso:*" />
  553. <xsl:variable name="theContainedFragments"
  554. select="$theDocument_2/*/schold:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
  555. <xsl:if test="not($theDocument_2)">
  556. <xsl:message terminate="no">
  557. <xsl:text>Unable to open referenced included file: </xsl:text>
  558. <xsl:value-of select="@href" />
  559. </xsl:message>
  560. </xsl:if>
  561. <xsl:if
  562. test=" $theFragment_2/self::schold:schema or $theContainedFragments/self::schold:schema">
  563. <xsl:message>
  564. Schema error: Use include to include
  565. fragments, not a whole schema
  566. </xsl:message>
  567. </xsl:if>
  568. <xsl:if
  569. test="not($theFragment_2) and not ($theContainedFragments)">
  570. <xsl:message terminate="no">
  571. <xsl:text>Unable to locate id attribute: </xsl:text>
  572. <xsl:value-of select="@href" />
  573. </xsl:message>
  574. </xsl:if>
  575. <!-- If this were XLST 2, we could use
  576. if ($theFragment) then $theFragment else $theContainedFragments
  577. here (thanks to KN)
  578. -->
  579. <xsl:choose>
  580. <xsl:when test=" $theFragment_2 ">
  581. <xsl:apply-templates
  582. select="$theFragment_2 " mode="dsdl:go" />
  583. </xsl:when>
  584. <xsl:otherwise>
  585. <!-- WARNING! EXPERIMENTAL! Use at your own risk. This may be discontinued! -->
  586. <xsl:apply-templates
  587. select=" $theContainedFragments " mode="dsdl:go" />
  588. </xsl:otherwise>
  589. </xsl:choose>
  590. </xsl:otherwise>
  591. </xsl:choose>
  592. </xsl:otherwise>
  593. </xsl:choose>
  594. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  595. <xsl:value-of select="@href" />
  596. </xsl:processing-instruction>
  597. </xsl:template>
  598. <!-- =========================================================== -->
  599. <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
  600. <!-- Part 5 - DataType Library Language - DTLL -->
  601. <!-- Committee Draft Experimental support only -->
  602. <!-- The <include> element may well be replaced by XInclude in -->
  603. <!-- any final version. -->
  604. <!-- =========================================================== -->
  605. <xslt:template match="dtll:include" mode="dsdl:go">
  606. <!-- Insert subschema -->
  607. <xsl:variable name="document-uri"
  608. select="substring-before(concat(@href,'#'), '#')" />
  609. <xsl:variable name="fragment-id"
  610. select="substring-after(@href, '#')" />
  611. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  612. <xsl:value-of select="@href" />
  613. </xsl:processing-instruction>
  614. <xsl:choose>
  615. <xsl:when test="not( $include-dtll = 'true' )">
  616. <xslt:copy>
  617. <xslt:copy-of select="@*" />
  618. <xslt:apply-templates mode="dsdl:go" />
  619. </xslt:copy>
  620. </xsl:when>
  621. <xsl:otherwise>
  622. <xsl:choose>
  623. <xsl:when
  624. test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
  625. <xsl:message>
  626. Error: Impossible URL in DTLL include
  627. </xsl:message>
  628. </xsl:when>
  629. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  630. <xslt:when
  631. test="string-length( $document-uri ) = 0">
  632. <xslt:apply-templates mode="dsdl:go"
  633. select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
  634. | //*[@id= $fragment-id ]" />
  635. </xslt:when>
  636. <xsl:when
  637. test="string-length( $fragment-id ) &gt; 0">
  638. <xsl:variable name="theDocument_1"
  639. select="document( $document-uri,/ )" />
  640. <xsl:if test="not($theDocument_1)">
  641. <xsl:message terminate="no">
  642. <xsl:text>Unable to open referenced included file: </xsl:text>
  643. <xsl:value-of select="@href" />
  644. </xsl:message>
  645. </xsl:if>
  646. <!-- use for-each to rebase id() to $theDocument -->
  647. <xsl:for-each select="$theDocument_1">
  648. <xsl:variable name="theFragment_1"
  649. select="$theDocument_1//*[@xml:id= $fragment-id ]
  650. | id( $fragment-id )
  651. | $theDocument_1//*[@id= $fragment-id ]" />
  652. <xsl:if test="not($theFragment_1)">
  653. <xsl:message terminate="no">
  654. <xsl:text>Unable to locate id attribute: </xsl:text>
  655. <xsl:value-of select="@href" />
  656. </xsl:message>
  657. </xsl:if>
  658. <xsl:apply-templates
  659. select=" $theFragment_1[1]" mode="dsdl:go" />
  660. </xsl:for-each>
  661. </xsl:when>
  662. <xsl:otherwise>
  663. <xsl:variable name="theDocument_2"
  664. select="document( $document-uri,/ )" />
  665. <xsl:variable name="theFragment_2"
  666. select="$theDocument_2/*" />
  667. <xsl:if test="not($theDocument_2)">
  668. <xsl:message terminate="no">
  669. <xsl:text>Unable to open referenced included file: </xsl:text>
  670. <xsl:value-of select="@href" />
  671. </xsl:message>
  672. </xsl:if>
  673. <xsl:if test="not($theFragment_2)">
  674. <xsl:message terminate="no">
  675. <xsl:text>Unable to locate id attribute: </xsl:text>
  676. <xsl:value-of select="@href" />
  677. </xsl:message>
  678. </xsl:if>
  679. <xsl:apply-templates select="$theFragment_2 "
  680. mode="dsdl:go" />
  681. </xsl:otherwise>
  682. </xsl:choose>
  683. </xsl:otherwise>
  684. </xsl:choose>
  685. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  686. <xsl:value-of select="@href" />
  687. </xsl:processing-instruction>
  688. </xslt:template>
  689. <!-- =========================================================== -->
  690. <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
  691. <!-- Part 7 - Character Repertoire Description Language - CRDL -->
  692. <!-- Final Committee Draft 2008-01-11 Experimental support only -->
  693. <!-- =========================================================== -->
  694. <xslt:template match="crdl:ref" mode="dsdl:go">
  695. <!-- Insert subschema -->
  696. <xsl:variable name="document-uri"
  697. select="substring-before(concat(@href,'#'), '#')" />
  698. <xsl:variable name="fragment-id"
  699. select="substring-after(@href, '#')" />
  700. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  701. <xsl:value-of select="@href" />
  702. </xsl:processing-instruction>
  703. <xsl:choose>
  704. <xsl:when test="not( $include-crdl = 'true' )">
  705. <xslt:copy>
  706. <xslt:copy-of select="@*" />
  707. <xslt:apply-templates mode="dsdl:go" />
  708. </xslt:copy>
  709. </xsl:when>
  710. <xsl:otherwise>
  711. <xsl:choose>
  712. <xsl:when
  713. test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
  714. <xsl:message>
  715. Error: Impossible URL in CRDL include
  716. </xsl:message>
  717. </xsl:when>
  718. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  719. <xslt:when
  720. test="string-length( $document-uri ) = 0">
  721. <xslt:apply-templates mode="dsdl:go"
  722. select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
  723. | //*[@id= $fragment-id ]" />
  724. </xslt:when>
  725. <xsl:when
  726. test="string-length( $fragment-id ) &gt; 0">
  727. <xsl:variable name="theDocument_1"
  728. select="document( $document-uri,/ )" />
  729. <xsl:if test="not($theDocument_1)">
  730. <xsl:message terminate="no">
  731. <xsl:text>Unable to open referenced included file: </xsl:text>
  732. <xsl:value-of select="@href" />
  733. </xsl:message>
  734. </xsl:if>
  735. <!-- use for-each to rebase id() to $theDocument -->
  736. <xsl:for-each select="$theDocument_1">
  737. <xsl:variable name="theFragment_1"
  738. select="$theDocument_1//*[@xml:id= $fragment-id ]
  739. | id( $fragment-id )
  740. | $theDocument_1//*[@id= $fragment-id ]" />
  741. <xsl:if test="not($theFragment_1)">
  742. <xsl:message terminate="no">
  743. <xsl:text>Unable to locate id attribute: </xsl:text>
  744. <xsl:value-of select="@href" />
  745. </xsl:message>
  746. </xsl:if>
  747. <xsl:apply-templates select=" $theFragment_1 "
  748. mode="dsdl:go" />
  749. </xsl:for-each>
  750. </xsl:when>
  751. <xsl:otherwise>
  752. <xsl:variable name="theDocument_2"
  753. select="document( $document-uri,/ )" />
  754. <xsl:variable name="theFragment_2"
  755. select="$theDocument_2/*" />
  756. <xsl:if test="not($theDocument_2)">
  757. <xsl:message terminate="no">
  758. <xsl:text>Unable to open referenced included file: </xsl:text>
  759. <xsl:value-of select="@href" />
  760. </xsl:message>
  761. </xsl:if>
  762. <xsl:if test="not($theFragment_2)">
  763. <xsl:message terminate="no">
  764. <xsl:text>Unable to locate id attribute: </xsl:text>
  765. <xsl:value-of select="@href" />
  766. </xsl:message>
  767. </xsl:if>
  768. <xsl:apply-templates select="$theFragment_2"
  769. mode="dsdl:go" />
  770. </xsl:otherwise>
  771. </xsl:choose>
  772. </xsl:otherwise>
  773. </xsl:choose>
  774. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  775. <xsl:value-of select="@href" />
  776. </xsl:processing-instruction>
  777. </xslt:template>
  778. <!-- =========================================================== -->
  779. <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
  780. <!-- Part 4 - Namespace-based Validation Dispatching Language - NVDL -->
  781. <!-- Note: This does not include schemas referenced for -->
  782. <!-- validation, it merely handles any simple XIncludes -->
  783. <!-- =========================================================== -->
  784. <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
  785. <!-- Part 8 - Document Schema Renaming Language - DSRL -->
  786. <!-- Note: Final? Committee Draft Experimental support only -->
  787. <!-- =========================================================== -->
  788. <!-- XInclude support for id based references only, with 1 level -->
  789. <!-- of fallback. -->
  790. <!-- =========================================================== -->
  791. <xslt:template mode="dsdl:go"
  792. match="xi:include[@href][not(@parseType) or @parseType ='xml']">
  793. <!-- Simple inclusions only here -->
  794. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  795. <xsl:value-of select="@href" />
  796. </xsl:processing-instruction>
  797. <xsl:choose>
  798. <xsl:when test="not( $include-xinclude = 'true' )">
  799. <xslt:copy>
  800. <xslt:copy-of select="@*" />
  801. <xslt:apply-templates mode="dsdl:go" />
  802. </xslt:copy>
  803. </xsl:when>
  804. <xsl:otherwise>
  805. <xsl:choose>
  806. <xsl:when test="contains( @href, '#')">
  807. <xsl:message terminate="yes">
  808. Fatal error: Xinclude href contains fragment
  809. identifier #
  810. </xsl:message>
  811. </xsl:when>
  812. <xsl:when test="contains( @xpointer, '(')">
  813. <xsl:message terminate="yes">
  814. Fatal error: Sorry, this software only
  815. supports simple ids in XInclude xpointers
  816. </xsl:message>
  817. </xsl:when>
  818. <xsl:when
  819. test="string-length( @href ) = 0 and string-length( @xpointer ) = 0">
  820. <xsl:message terminate="yes">
  821. Fatal Error: Impossible URL in XInclude
  822. include
  823. </xsl:message>
  824. </xsl:when>
  825. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  826. <xslt:when test="string-length( @href ) = 0">
  827. <xslt:apply-templates mode="dsdl:go"
  828. select="//*[@xml:id= current()/@xpointer ] | id( @xpointer)
  829. | //*[@id= current()/@xpointer ]" />
  830. </xslt:when>
  831. <xsl:when
  832. test="string-length( @xpointer ) &gt; 0">
  833. <xsl:variable name="theDocument_1"
  834. select="document( @href,/ )" />
  835. <xsl:variable name="theFragment_1"
  836. select="$theDocument_1//*[@xml:id= current()/@xpointer ]
  837. | $theDocument_1//*[@id= current()/@xpointer ]" />
  838. <!-- removed
  839. | $theDocument_1/id( @xpointer)
  840. because it requires rebasing in XSLT1 and that would mess up the use of current()
  841. -->
  842. <!-- Allow one level of fallback, to another XInclude -->
  843. <xsl:if test="not($theDocument_1)">
  844. <xsl:choose>
  845. <xsl:when test="xi:fallback">
  846. <xsl:variable name="theDocument_2"
  847. select="document( xi:fallback[1]/xi:include[not(@parseType)
  848. or @parseType='xml']/@href,/ )" />
  849. <xsl:variable name="theFragment_2"
  850. select="$theDocument_2//*[@xml:id= current()/xi:fallback[1]/xi:include/@xpointer ]
  851. | $theDocument_2//*[@id= current()/xi:fallback[1]/xi:include/@xpointer ]" />
  852. <!-- removed
  853. | $theDocument_2/id( xi:fallback[1]/xi:include/@xpointer)
  854. because it id() would need rebasing in XSLT1 and that would mess up use of current()
  855. -->
  856. <xsl:if
  857. test="not($theDocument_2)">
  858. <xsl:message terminate="no">
  859. <xsl:text>Unable to open referenced included file and fallback
  860. file: </xsl:text>
  861. <xsl:value-of
  862. select="@href" />
  863. </xsl:message>
  864. </xsl:if>
  865. </xsl:when>
  866. <xsl:otherwise>
  867. <xsl:message terminate="no">
  868. <xsl:text>Unable to open referenced included file: </xsl:text>
  869. <xsl:value-of select="@href" />
  870. </xsl:message>
  871. </xsl:otherwise>
  872. </xsl:choose>
  873. </xsl:if>
  874. <xsl:apply-templates select=" $theFragment_1"
  875. mode="dsdl:go" />
  876. </xsl:when>
  877. <!-- Document but no fragment specified -->
  878. <xsl:otherwise>
  879. <xsl:variable name="theDocument_3"
  880. select="document( @href,/ )" />
  881. <xsl:variable name="theFragment_3"
  882. select="$theDocument_3/*" />
  883. <xsl:if test="not($theDocument_3)">
  884. <xsl:message terminate="no">
  885. <xsl:text>Unable to open referenced included file: </xsl:text>
  886. <xsl:value-of select="@href" />
  887. </xsl:message>
  888. </xsl:if>
  889. <xsl:apply-templates select="$theFragment_3 "
  890. mode="dsdl:go" />
  891. </xsl:otherwise>
  892. </xsl:choose>
  893. </xsl:otherwise>
  894. </xsl:choose>
  895. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  896. <xsl:value-of select="@href" />
  897. </xsl:processing-instruction>
  898. </xslt:template>
  899. <!-- =========================================================== -->
  900. <!-- W3C XLink 1.1 embedded simple links -->
  901. <!-- =========================================================== -->
  902. <xslt:template
  903. match="*[@xlink:href][not(parent::*[@xlink:type='complex'])]
  904. [not(@xlink:type) or (@xlink:type='simple')]
  905. [@xlink:show='embed']
  906. [not(@xlink:actuate) or (@xlink:actuate='onLoad')]"
  907. mode="dsdl:go" priority="1">
  908. <xsl:variable name="document-uri"
  909. select="substring-before(concat(@xlink:href,'#'), '#')" />
  910. <xsl:variable name="fragment-id"
  911. select="substring-after(@xlink:href, '#')" />
  912. <xsl:processing-instruction name="DSDL_INCLUDE_START">
  913. <xsl:value-of select="@xlink:href" />
  914. </xsl:processing-instruction>
  915. <xsl:choose>
  916. <xsl:when test="not( $include-xlink = 'true' )">
  917. <xslt:copy>
  918. <xslt:copy-of select="@*" />
  919. <xslt:apply-templates mode="dsdl:go" />
  920. </xslt:copy>
  921. </xsl:when>
  922. <xsl:otherwise>
  923. <xsl:choose>
  924. <xsl:when
  925. test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
  926. <xsl:message>
  927. Error: Impossible URL in XLink embedding
  928. link
  929. </xsl:message>
  930. </xsl:when>
  931. <!-- this case is when there is in embedded schema in the same document elsewhere -->
  932. <xslt:when
  933. test="string-length( $document-uri ) = 0">
  934. <xslt:apply-templates mode="dsdl:go"
  935. select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
  936. | //*[@id= $fragment-id ]" />
  937. </xslt:when>
  938. <xsl:when
  939. test="string-length( $fragment-id ) &gt; 0">
  940. <xsl:variable name="theDocument_1"
  941. select="document( $document-uri,/ )" />
  942. <xsl:if test="not($theDocument_1)">
  943. <xsl:message terminate="no">
  944. <xsl:text>Unable to open referenced included file: </xsl:text>
  945. <xsl:value-of select="@xlink:href" />
  946. </xsl:message>
  947. </xsl:if>
  948. <!-- use for-each to rebase id() to $theDocument -->
  949. <xsl:for-each select="$theDocument_1">
  950. <xsl:variable name="theFragment_1"
  951. select="$theDocument_1//*[@xml:id= $fragment-id ]
  952. | id( $fragment-id )
  953. | $theDocument_1//*[@id= $fragment-id ]" />
  954. <xsl:if test="not($theFragment_1)">
  955. <xsl:message terminate="no">
  956. <xsl:text>Unable to locate id attribute: </xsl:text>
  957. <xsl:value-of select="@xlink:href" />
  958. </xsl:message>
  959. </xsl:if>
  960. <xsl:apply-templates
  961. select=" $theFragment_1[1]" mode="dsdl:go" />
  962. </xsl:for-each>
  963. </xsl:when>
  964. <xsl:otherwise>
  965. <xsl:variable name="theDocument_2"
  966. select="document( $document-uri,/ )" />
  967. <xsl:variable name="theFragment_2"
  968. select="$theDocument_2/*" />
  969. <xsl:if test="not($theDocument_2)">
  970. <xsl:message terminate="no">
  971. <xsl:text>Unable to open referenced included file: </xsl:text>
  972. <xsl:value-of select="@xlink:href" />
  973. </xsl:message>
  974. </xsl:if>
  975. <xsl:if test="not($theFragment_2)">
  976. <xsl:message terminate="no">
  977. <xsl:text>Unable to locate id attribute: </xsl:text>
  978. <xsl:value-of select="@xlink:href" />
  979. </xsl:message>
  980. </xsl:if>
  981. <xsl:apply-templates select="$theFragment_2 "
  982. mode="dsdl:go" />
  983. </xsl:otherwise>
  984. </xsl:choose>
  985. </xsl:otherwise>
  986. </xsl:choose>
  987. <xsl:processing-instruction name="DSDL_INCLUDE_END">
  988. <xsl:value-of select="@xlink:href" />
  989. </xsl:processing-instruction>
  990. </xslt:template>
  991. </xslt:stylesheet>