embedded.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. Name: embedded.xsl
  4. Purpose: Used by check.sh for offline checking of the configuration.
  5. Author: Mike Wetherell
  6. Copyright: (c) 2007 Mike Wetherell
  7. Licence: wxWindows licence
  8. -->
  9. <transform xmlns="http://www.w3.org/1999/XSL/Transform"
  10. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  11. xmlns:XSL="XSL"
  12. version="1.0">
  13. <namespace-alias stylesheet-prefix="XSL" result-prefix="xsl"/>
  14. <output indent="yes"/>
  15. <variable
  16. name="root"
  17. select="//*[not(ancestor-or-self::*[name() != name(/*)])]"/>
  18. <variable
  19. name="includes"
  20. select="$root[position() > 1]"/>
  21. <variable
  22. xmlns:func="http://exslt.org/functions"
  23. name="top-level"
  24. select="$root/xsl:import |
  25. $root/xsl:include |
  26. $root/xsl:attribute-set |
  27. $root/xsl:character-map |
  28. $root/xsl:decimal-format |
  29. $root/xsl:function |
  30. $root/xsl:import-schema |
  31. $root/xsl:key |
  32. $root/xsl:namespace-alias |
  33. $root/xsl:output |
  34. $root/xsl:param |
  35. $root/xsl:preserve-space |
  36. $root/xsl:strip-space |
  37. $root/xsl:template |
  38. $root/xsl:variable |
  39. $root/func:function"/>
  40. <template match="/">
  41. <XSL:transform>
  42. <copy-of select="$root/namespace::*"/>
  43. <for-each select="$root/@xsl:*">
  44. <attribute name="{local-name()}">
  45. <value-of select="."/>
  46. </attribute>
  47. </for-each>
  48. <for-each select="$top-level">
  49. <if test="not(../ancestor::*/*[name() = name(current()) and @name = current()/@name])">
  50. <apply-templates mode="copy-xsl" select="."/>
  51. </if>
  52. </for-each>
  53. <apply-templates select="*"/>
  54. </XSL:transform>
  55. </template>
  56. <template match="*">
  57. <variable name="pattern">
  58. <call-template name="coord-pattern"/>
  59. </variable>
  60. <variable name="is-xsl">
  61. <call-template name="is-xsl"/>
  62. </variable>
  63. <XSL:template match="*[generate-id() = generate-id(document('', /){$pattern})]">
  64. <copy-of select="namespace::*"/>
  65. <choose>
  66. <when test="$root/xsl:template[@name = name(current())]">
  67. <call-template name="expand">
  68. <with-param name="inside-xsl" select="$is-xsl = 'true'"/>
  69. </call-template>
  70. </when>
  71. <when test="count($includes | .) = count($includes)">
  72. <if test="node()">
  73. <XSL:apply-templates select="node()"/>
  74. </if>
  75. </when>
  76. <when test="count($top-level | .) != count($top-level)">
  77. <call-template name="create-context"/>
  78. </when>
  79. </choose>
  80. </XSL:template>
  81. <if test="$is-xsl != 'true'">
  82. <apply-templates select="node()"/>
  83. </if>
  84. </template>
  85. <template match="text()"/>
  86. <template match="@*">
  87. <copy/>
  88. </template>
  89. <template mode="copy-xsl" match="*[//xsl:template[not(ancestor::*[name() != name(/*)])]/@name = name()]">
  90. <choose>
  91. <when test="ancestor::xsl:template[@name = name(current())]">
  92. <copy>
  93. <call-template name="copy-xsl-children"/>
  94. </copy>
  95. </when>
  96. <otherwise>
  97. <call-template name="expand">
  98. <with-param name="inside-xsl" select="true()"/>
  99. </call-template>
  100. </otherwise>
  101. </choose>
  102. </template>
  103. <template mode="copy-xsl" match="@*|node()">
  104. <copy>
  105. <call-template name="copy-xsl-children"/>
  106. </copy>
  107. </template>
  108. <template name="copy-xsl-children">
  109. <copy-of select="namespace::*"/>
  110. <apply-templates mode="copy-xsl" select="@*|node()"/>
  111. </template>
  112. <template name="coord-pattern">
  113. <param name="element" select="."/>
  114. <for-each select="$element/ancestor-or-self::*">
  115. <text>/*[</text>
  116. <value-of select="count(preceding-sibling::*) + 1"/>
  117. <text>]</text>
  118. </for-each>
  119. </template>
  120. <template name="is-xsl">
  121. <param name="element" select="."/>
  122. <choose>
  123. <when test="$element/self::xsl:*">
  124. <value-of select="true()"/>
  125. </when>
  126. <otherwise>
  127. <variable name="namespace" select="namespace-uri($element)"/>
  128. <variable name="extension-namespaces">
  129. <for-each select="$element/ancestor-or-self::*/@xsl:extension-element-prefixes">
  130. <variable name="prefixes"
  131. select="concat(' ', normalize-space(.), ' ')"/>
  132. <variable name="namespaces"
  133. select="../namespace::*[contains($prefixes, concat(' ', name(), ' ')) or
  134. (name() = '' and contains($prefixes, ' #default '))]"/>
  135. <value-of select="$namespaces[. = $namespace]"/>
  136. </for-each>
  137. </variable>
  138. <value-of select="$extension-namespaces != ''"/>
  139. </otherwise>
  140. </choose>
  141. </template>
  142. <template name="expand">
  143. <param name="inside-xsl"/>
  144. <variable name="params" select="$root/xsl:template[@name = name(current())]/xsl:param"/>
  145. <XSL:call-template name="{name()}">
  146. <if test="node() and $params">
  147. <XSL:with-param name="{$params[1]/@name}">
  148. <choose>
  149. <when test="$inside-xsl">
  150. <apply-templates mode="copy-xsl" select="node()"/>
  151. </when>
  152. <otherwise>
  153. <variable name="pattern">
  154. <call-template name="coord-pattern"/>
  155. </variable>
  156. <XSL:apply-templates select="{$pattern}/node()"/>
  157. </otherwise>
  158. </choose>
  159. </XSL:with-param>
  160. </if>
  161. <for-each select="@*">
  162. <variable name="len" select="string-length(.)"/>
  163. <choose>
  164. <when test="substring(., 1, 1) = '{' and
  165. substring(., $len, 1) = '}'">
  166. <XSL:with-param name="{name()}"
  167. select="{substring(., 2, $len - 2)}"/>
  168. </when>
  169. <otherwise>
  170. <XSL:with-param name="{name()}">
  171. <call-template name="avt"/>
  172. </XSL:with-param>
  173. </otherwise>
  174. </choose>
  175. </for-each>
  176. </XSL:call-template>
  177. </template>
  178. <template name="create-context">
  179. <param name="elements" select="ancestor-or-self::*
  180. [last() - 1 > position()]
  181. /preceding-sibling::xsl:variable | ."/>
  182. <variable name="pattern">
  183. <call-template name="coord-pattern">
  184. <with-param name="element" select="$elements[1]"/>
  185. </call-template>
  186. </variable>
  187. <variable name="parent-pattern">
  188. <call-template name="coord-pattern">
  189. <with-param name="element" select="$elements[1]/.."/>
  190. </call-template>
  191. </variable>
  192. <XSL:for-each select="{$parent-pattern}/*">
  193. <XSL:if test="count({$pattern} | .) = 1">
  194. <variable name="is-xsl">
  195. <call-template name="is-xsl">
  196. <with-param name="element" select="$elements[1]"/>
  197. </call-template>
  198. </variable>
  199. <choose>
  200. <when test="$is-xsl = 'true'">
  201. <apply-templates mode="copy-xsl" select="$elements[1]"/>
  202. <if test="$elements[2]">
  203. <call-template name="create-context">
  204. <with-param name="elements" select="$elements[position() > 1]"/>
  205. </call-template>
  206. </if>
  207. </when>
  208. <otherwise>
  209. <copy>
  210. <apply-templates select="@*"/>
  211. <if test="node()">
  212. <XSL:apply-templates select="node()"/>
  213. </if>
  214. </copy>
  215. </otherwise>
  216. </choose>
  217. </XSL:if>
  218. </XSL:for-each>
  219. </template>
  220. <template name="before">
  221. <param name="string"/>
  222. <param name="target"/>
  223. <variable name="apos">'</variable>
  224. <variable name="quot">"</variable>
  225. <variable name="posapos" select="string-length(substring-before(
  226. concat($string, $apos), $apos))"/>
  227. <variable name="posquot" select="string-length(substring-before(
  228. concat($string, $quot), $quot))"/>
  229. <variable name="postarg" select="string-length(substring-before(
  230. concat($string, $target), $target))"/>
  231. <choose>
  232. <when test="$posapos = $postarg and $posquot = $postarg">
  233. <value-of select="$string"/>
  234. </when>
  235. <when test="$posapos > $postarg and $posquot > $postarg">
  236. <value-of select="substring($string, 1, $postarg)"/>
  237. </when>
  238. <otherwise>
  239. <variable name="delim">
  240. <choose>
  241. <when test="$posquot > $posapos">'</when>
  242. <otherwise>"</otherwise>
  243. </choose>
  244. </variable>
  245. <value-of select="substring-before($string, $delim)"/>
  246. <value-of select="$delim"/>
  247. <variable name="mid" select="substring-after($string, $delim)"/>
  248. <choose>
  249. <when test="contains($mid, $delim)">
  250. <value-of select="substring-before($mid, $delim)"/>
  251. <value-of select="$delim"/>
  252. <call-template name="before">
  253. <with-param name="string"
  254. select="substring-after($mid, $delim)"/>
  255. <with-param name="target"
  256. select="$target"/>
  257. </call-template>
  258. </when>
  259. <otherwise>
  260. <value-of select="$mid"/>
  261. </otherwise>
  262. </choose>
  263. </otherwise>
  264. </choose>
  265. </template>
  266. <template name="avt">
  267. <param name="string" select="."/>
  268. <variable name="before1" select="substring-before(concat($string, '{'), '{')"/>
  269. <variable name="len1" select="string-length($before1)"/>
  270. <variable name="before2" select="substring-before(concat($string, '}}'), '}}')"/>
  271. <variable name="len2" select="string-length($before2)"/>
  272. <choose>
  273. <when test="$before1 = $string and $before2 = $string">
  274. <value-of select="$string"/>
  275. </when>
  276. <when test="$len2 &lt; $len1">
  277. <value-of select="$before2"/>
  278. <text>}</text>
  279. <call-template name="avt">
  280. <with-param name="string" select="substring($string, $len2 + 3)"/>
  281. </call-template>
  282. </when>
  283. <when test="substring($string, $len1 + 2, 1) = '{'">
  284. <value-of select="$before1"/>
  285. <text>{</text>
  286. <call-template name="avt">
  287. <with-param name="string" select="substring($string, $len1 + 3)"/>
  288. </call-template>
  289. </when>
  290. <otherwise>
  291. <variable name="mid" select="substring($string, $len1 + 2)"/>
  292. <variable name="expr">
  293. <call-template name="before">
  294. <with-param name="string" select="$mid"/>
  295. <with-param name="target">}</with-param>
  296. </call-template>
  297. </variable>
  298. <value-of select="$before1"/>
  299. <XSL:copy-of select="{$expr}"/>
  300. <call-template name="avt">
  301. <with-param name="string" select="substring($mid, string-length($expr) + 2)"/>
  302. </call-template>
  303. </otherwise>
  304. </choose>
  305. </template>
  306. </transform>