profile-mode.xsl 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:saxon="http://icl.com/saxon"
  3. exclude-result-prefixes="saxon"
  4. version="1.0">
  5. <!-- Should be base URI for imagedata and so on fixed? -->
  6. <xsl:param name="profile.baseuri.fixup" select="true()"/>
  7. <!-- Copy all non-element nodes -->
  8. <xsl:template match="@*|text()|comment()|processing-instruction()" mode="profile">
  9. <xsl:copy/>
  10. </xsl:template>
  11. <!-- Profile elements based on input parameters -->
  12. <xsl:template match="*" mode="profile">
  13. <xsl:variable name="arch.content">
  14. <xsl:if test="@arch">
  15. <xsl:call-template name="cross.compare">
  16. <xsl:with-param name="a" select="$profile.arch"/>
  17. <xsl:with-param name="b" select="@arch"/>
  18. </xsl:call-template>
  19. </xsl:if>
  20. </xsl:variable>
  21. <xsl:variable name="arch.ok" select="not(@arch) or not($profile.arch) or
  22. $arch.content != '' or @arch = ''"/>
  23. <xsl:variable name="audience.content">
  24. <xsl:if test="@audience">
  25. <xsl:call-template name="cross.compare">
  26. <xsl:with-param name="a" select="$profile.audience"/>
  27. <xsl:with-param name="b" select="@audience"/>
  28. </xsl:call-template>
  29. </xsl:if>
  30. </xsl:variable>
  31. <xsl:variable name="audience.ok"
  32. select="not(@audience) or not($profile.audience) or
  33. $audience.content != '' or @audience = ''"/>
  34. <xsl:variable name="condition.content">
  35. <xsl:if test="@condition">
  36. <xsl:call-template name="cross.compare">
  37. <xsl:with-param name="a" select="$profile.condition"/>
  38. <xsl:with-param name="b" select="@condition"/>
  39. </xsl:call-template>
  40. </xsl:if>
  41. </xsl:variable>
  42. <xsl:variable name="condition.ok" select="not(@condition) or not($profile.condition) or
  43. $condition.content != '' or @condition = ''"/>
  44. <xsl:variable name="conformance.content">
  45. <xsl:if test="@conformance">
  46. <xsl:call-template name="cross.compare">
  47. <xsl:with-param name="a" select="$profile.conformance"/>
  48. <xsl:with-param name="b" select="@conformance"/>
  49. </xsl:call-template>
  50. </xsl:if>
  51. </xsl:variable>
  52. <xsl:variable name="conformance.ok" select="not(@conformance) or not($profile.conformance) or
  53. $conformance.content != '' or @conformance = ''"/>
  54. <xsl:variable name="lang.content">
  55. <xsl:if test="@lang | @xml:lang">
  56. <xsl:call-template name="cross.compare">
  57. <xsl:with-param name="a" select="$profile.lang"/>
  58. <xsl:with-param name="b" select="(@lang | @xml:lang)[1]"/>
  59. </xsl:call-template>
  60. </xsl:if>
  61. </xsl:variable>
  62. <xsl:variable name="lang.ok" select="not(@lang | @xml:lang) or not($profile.lang) or
  63. $lang.content != '' or @lang = '' or @xml:lang = ''"/>
  64. <xsl:variable name="os.content">
  65. <xsl:if test="@os">
  66. <xsl:call-template name="cross.compare">
  67. <xsl:with-param name="a" select="$profile.os"/>
  68. <xsl:with-param name="b" select="@os"/>
  69. </xsl:call-template>
  70. </xsl:if>
  71. </xsl:variable>
  72. <xsl:variable name="os.ok" select="not(@os) or not($profile.os) or
  73. $os.content != '' or @os = ''"/>
  74. <xsl:variable name="revision.content">
  75. <xsl:if test="@revision">
  76. <xsl:call-template name="cross.compare">
  77. <xsl:with-param name="a" select="$profile.revision"/>
  78. <xsl:with-param name="b" select="@revision"/>
  79. </xsl:call-template>
  80. </xsl:if>
  81. </xsl:variable>
  82. <xsl:variable name="revision.ok" select="not(@revision) or not($profile.revision) or
  83. $revision.content != '' or @revision = ''"/>
  84. <xsl:variable name="revisionflag.content">
  85. <xsl:if test="@revisionflag">
  86. <xsl:call-template name="cross.compare">
  87. <xsl:with-param name="a" select="$profile.revisionflag"/>
  88. <xsl:with-param name="b" select="@revisionflag"/>
  89. </xsl:call-template>
  90. </xsl:if>
  91. </xsl:variable>
  92. <xsl:variable name="revisionflag.ok" select="not(@revisionflag) or not($profile.revisionflag) or
  93. $revisionflag.content != '' or @revisionflag = ''"/>
  94. <xsl:variable name="role.content">
  95. <xsl:if test="@role">
  96. <xsl:call-template name="cross.compare">
  97. <xsl:with-param name="a" select="$profile.role"/>
  98. <xsl:with-param name="b" select="@role"/>
  99. </xsl:call-template>
  100. </xsl:if>
  101. </xsl:variable>
  102. <xsl:variable name="role.ok" select="not(@role) or not($profile.role) or
  103. $role.content != '' or @role = ''"/>
  104. <xsl:variable name="security.content">
  105. <xsl:if test="@security">
  106. <xsl:call-template name="cross.compare">
  107. <xsl:with-param name="a" select="$profile.security"/>
  108. <xsl:with-param name="b" select="@security"/>
  109. </xsl:call-template>
  110. </xsl:if>
  111. </xsl:variable>
  112. <xsl:variable name="security.ok" select="not(@security) or not($profile.security) or
  113. $security.content != '' or @security = ''"/>
  114. <xsl:variable name="status.content">
  115. <xsl:if test="@status">
  116. <xsl:call-template name="cross.compare">
  117. <xsl:with-param name="a" select="$profile.status"/>
  118. <xsl:with-param name="b" select="@status"/>
  119. </xsl:call-template>
  120. </xsl:if>
  121. </xsl:variable>
  122. <xsl:variable name="status.ok" select="not(@status) or not($profile.status) or
  123. $status.content != '' or @status = ''"/>
  124. <xsl:variable name="userlevel.content">
  125. <xsl:if test="@userlevel">
  126. <xsl:call-template name="cross.compare">
  127. <xsl:with-param name="a" select="$profile.userlevel"/>
  128. <xsl:with-param name="b" select="@userlevel"/>
  129. </xsl:call-template>
  130. </xsl:if>
  131. </xsl:variable>
  132. <xsl:variable name="userlevel.ok" select="not(@userlevel) or not($profile.userlevel) or
  133. $userlevel.content != '' or @userlevel = ''"/>
  134. <xsl:variable name="vendor.content">
  135. <xsl:if test="@vendor">
  136. <xsl:call-template name="cross.compare">
  137. <xsl:with-param name="a" select="$profile.vendor"/>
  138. <xsl:with-param name="b" select="@vendor"/>
  139. </xsl:call-template>
  140. </xsl:if>
  141. </xsl:variable>
  142. <xsl:variable name="vendor.ok" select="not(@vendor) or not($profile.vendor) or
  143. $vendor.content != '' or @vendor = ''"/>
  144. <xsl:variable name="wordsize.content">
  145. <xsl:if test="@wordsize">
  146. <xsl:call-template name="cross.compare">
  147. <xsl:with-param name="a" select="$profile.wordsize"/>
  148. <xsl:with-param name="b" select="@wordsize"/>
  149. </xsl:call-template>
  150. </xsl:if>
  151. </xsl:variable>
  152. <xsl:variable name="wordsize.ok"
  153. select="not(@wordsize) or not($profile.wordsize) or
  154. $wordsize.content != '' or @wordsize = ''"/>
  155. <xsl:variable name="attribute.content">
  156. <xsl:if test="@*[local-name()=$profile.attribute]">
  157. <xsl:call-template name="cross.compare">
  158. <xsl:with-param name="a" select="$profile.value"/>
  159. <xsl:with-param name="b" select="@*[local-name()=$profile.attribute]"/>
  160. </xsl:call-template>
  161. </xsl:if>
  162. </xsl:variable>
  163. <xsl:variable name="attribute.ok"
  164. select="not(@*[local-name()=$profile.attribute]) or
  165. not($profile.value) or $attribute.content != '' or
  166. @*[local-name()=$profile.attribute] = '' or
  167. not($profile.attribute)"/>
  168. <xsl:if test="$arch.ok and
  169. $audience.ok and
  170. $condition.ok and
  171. $conformance.ok and
  172. $lang.ok and
  173. $os.ok and
  174. $revision.ok and
  175. $revisionflag.ok and
  176. $role.ok and
  177. $security.ok and
  178. $status.ok and
  179. $userlevel.ok and
  180. $vendor.ok and
  181. $wordsize.ok and
  182. $attribute.ok">
  183. <xsl:copy>
  184. <xsl:copy-of select="@*"/>
  185. <!-- Entity references must be replaced with filereferences for temporary tree -->
  186. <xsl:if test="@entityref and $profile.baseuri.fixup">
  187. <xsl:attribute name="fileref">
  188. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  189. </xsl:attribute>
  190. </xsl:if>
  191. <!-- xml:base is eventually added to the root element -->
  192. <xsl:if test="not(../..) and $profile.baseuri.fixup">
  193. <xsl:call-template name="add-xml-base"/>
  194. </xsl:if>
  195. <xsl:apply-templates select="node()" mode="profile"/>
  196. </xsl:copy>
  197. </xsl:if>
  198. </xsl:template>
  199. <!-- Returns non-empty string if list in $b contains one ore more values from list $a -->
  200. <xsl:template name="cross.compare">
  201. <xsl:param name="a"/>
  202. <xsl:param name="b"/>
  203. <xsl:param name="sep" select="$profile.separator"/>
  204. <xsl:variable name="head" select="substring-before(concat($a, $sep), $sep)"/>
  205. <xsl:variable name="tail" select="substring-after($a, $sep)"/>
  206. <xsl:if test="contains(concat($sep, $b, $sep), concat($sep, $head, $sep))">1</xsl:if>
  207. <xsl:if test="$tail">
  208. <xsl:call-template name="cross.compare">
  209. <xsl:with-param name="a" select="$tail"/>
  210. <xsl:with-param name="b" select="$b"/>
  211. </xsl:call-template>
  212. </xsl:if>
  213. </xsl:template>
  214. </xsl:stylesheet>