profile-mode.xsl 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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="condition.content">
  24. <xsl:if test="@condition">
  25. <xsl:call-template name="cross.compare">
  26. <xsl:with-param name="a" select="$profile.condition"/>
  27. <xsl:with-param name="b" select="@condition"/>
  28. </xsl:call-template>
  29. </xsl:if>
  30. </xsl:variable>
  31. <xsl:variable name="condition.ok" select="not(@condition) or not($profile.condition) or
  32. $condition.content != '' or @condition = ''"/>
  33. <xsl:variable name="conformance.content">
  34. <xsl:if test="@conformance">
  35. <xsl:call-template name="cross.compare">
  36. <xsl:with-param name="a" select="$profile.conformance"/>
  37. <xsl:with-param name="b" select="@conformance"/>
  38. </xsl:call-template>
  39. </xsl:if>
  40. </xsl:variable>
  41. <xsl:variable name="conformance.ok" select="not(@conformance) or not($profile.conformance) or
  42. $conformance.content != '' or @conformance = ''"/>
  43. <xsl:variable name="lang.content">
  44. <xsl:if test="@lang | @xml:lang">
  45. <xsl:call-template name="cross.compare">
  46. <xsl:with-param name="a" select="$profile.lang"/>
  47. <xsl:with-param name="b" select="(@lang | @xml:lang)[1]"/>
  48. </xsl:call-template>
  49. </xsl:if>
  50. </xsl:variable>
  51. <xsl:variable name="lang.ok" select="not(@lang | @xml:lang) or not($profile.lang) or
  52. $lang.content != '' or @lang = '' or @xml:lang = ''"/>
  53. <xsl:variable name="os.content">
  54. <xsl:if test="@os">
  55. <xsl:call-template name="cross.compare">
  56. <xsl:with-param name="a" select="$profile.os"/>
  57. <xsl:with-param name="b" select="@os"/>
  58. </xsl:call-template>
  59. </xsl:if>
  60. </xsl:variable>
  61. <xsl:variable name="os.ok" select="not(@os) or not($profile.os) or
  62. $os.content != '' or @os = ''"/>
  63. <xsl:variable name="revision.content">
  64. <xsl:if test="@revision">
  65. <xsl:call-template name="cross.compare">
  66. <xsl:with-param name="a" select="$profile.revision"/>
  67. <xsl:with-param name="b" select="@revision"/>
  68. </xsl:call-template>
  69. </xsl:if>
  70. </xsl:variable>
  71. <xsl:variable name="revision.ok" select="not(@revision) or not($profile.revision) or
  72. $revision.content != '' or @revision = ''"/>
  73. <xsl:variable name="revisionflag.content">
  74. <xsl:if test="@revisionflag">
  75. <xsl:call-template name="cross.compare">
  76. <xsl:with-param name="a" select="$profile.revisionflag"/>
  77. <xsl:with-param name="b" select="@revisionflag"/>
  78. </xsl:call-template>
  79. </xsl:if>
  80. </xsl:variable>
  81. <xsl:variable name="revisionflag.ok" select="not(@revisionflag) or not($profile.revisionflag) or
  82. $revisionflag.content != '' or @revisionflag = ''"/>
  83. <xsl:variable name="role.content">
  84. <xsl:if test="@role">
  85. <xsl:call-template name="cross.compare">
  86. <xsl:with-param name="a" select="$profile.role"/>
  87. <xsl:with-param name="b" select="@role"/>
  88. </xsl:call-template>
  89. </xsl:if>
  90. </xsl:variable>
  91. <xsl:variable name="role.ok" select="not(@role) or not($profile.role) or
  92. $role.content != '' or @role = ''"/>
  93. <xsl:variable name="security.content">
  94. <xsl:if test="@security">
  95. <xsl:call-template name="cross.compare">
  96. <xsl:with-param name="a" select="$profile.security"/>
  97. <xsl:with-param name="b" select="@security"/>
  98. </xsl:call-template>
  99. </xsl:if>
  100. </xsl:variable>
  101. <xsl:variable name="security.ok" select="not(@security) or not($profile.security) or
  102. $security.content != '' or @security = ''"/>
  103. <xsl:variable name="status.content">
  104. <xsl:if test="@status">
  105. <xsl:call-template name="cross.compare">
  106. <xsl:with-param name="a" select="$profile.status"/>
  107. <xsl:with-param name="b" select="@status"/>
  108. </xsl:call-template>
  109. </xsl:if>
  110. </xsl:variable>
  111. <xsl:variable name="status.ok" select="not(@status) or not($profile.status) or
  112. $status.content != '' or @status = ''"/>
  113. <xsl:variable name="userlevel.content">
  114. <xsl:if test="@userlevel">
  115. <xsl:call-template name="cross.compare">
  116. <xsl:with-param name="a" select="$profile.userlevel"/>
  117. <xsl:with-param name="b" select="@userlevel"/>
  118. </xsl:call-template>
  119. </xsl:if>
  120. </xsl:variable>
  121. <xsl:variable name="userlevel.ok" select="not(@userlevel) or not($profile.userlevel) or
  122. $userlevel.content != '' or @userlevel = ''"/>
  123. <xsl:variable name="vendor.content">
  124. <xsl:if test="@vendor">
  125. <xsl:call-template name="cross.compare">
  126. <xsl:with-param name="a" select="$profile.vendor"/>
  127. <xsl:with-param name="b" select="@vendor"/>
  128. </xsl:call-template>
  129. </xsl:if>
  130. </xsl:variable>
  131. <xsl:variable name="vendor.ok" select="not(@vendor) or not($profile.vendor) or
  132. $vendor.content != '' or @vendor = ''"/>
  133. <xsl:variable name="attribute.content">
  134. <xsl:if test="@*[local-name()=$profile.attribute]">
  135. <xsl:call-template name="cross.compare">
  136. <xsl:with-param name="a" select="$profile.value"/>
  137. <xsl:with-param name="b" select="@*[local-name()=$profile.attribute]"/>
  138. </xsl:call-template>
  139. </xsl:if>
  140. </xsl:variable>
  141. <xsl:variable name="attribute.ok"
  142. select="not(@*[local-name()=$profile.attribute]) or not($profile.value) or
  143. $attribute.content != '' or
  144. @*[local-name()=$profile.attribute] = '' or not($profile.attribute)"/>
  145. <xsl:if test="$arch.ok and $condition.ok and $conformance.ok and $lang.ok and $os.ok
  146. and $revision.ok and $revisionflag.ok and $role.ok and $security.ok
  147. and $status.ok and $userlevel.ok and $vendor.ok and $attribute.ok">
  148. <xsl:copy>
  149. <xsl:copy-of select="@*"/>
  150. <!-- Entity references must be replaced with filereferences for temporary tree -->
  151. <xsl:if test="@entityref and $profile.baseuri.fixup">
  152. <xsl:attribute name="fileref">
  153. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  154. </xsl:attribute>
  155. </xsl:if>
  156. <!-- xml:base is eventually added to the root element -->
  157. <xsl:if test="not(../..) and $profile.baseuri.fixup">
  158. <xsl:call-template name="add-xml-base"/>
  159. </xsl:if>
  160. <xsl:apply-templates select="node()" mode="profile"/>
  161. </xsl:copy>
  162. </xsl:if>
  163. </xsl:template>
  164. <!-- Returns non-empty string if list in $b contains one ore more values from list $a -->
  165. <xsl:template name="cross.compare">
  166. <xsl:param name="a"/>
  167. <xsl:param name="b"/>
  168. <xsl:param name="sep" select="$profile.separator"/>
  169. <xsl:variable name="head" select="substring-before(concat($a, $sep), $sep)"/>
  170. <xsl:variable name="tail" select="substring-after($a, $sep)"/>
  171. <xsl:if test="contains(concat($sep, $b, $sep), concat($sep, $head, $sep))">1</xsl:if>
  172. <xsl:if test="$tail">
  173. <xsl:call-template name="cross.compare">
  174. <xsl:with-param name="a" select="$tail"/>
  175. <xsl:with-param name="b" select="$b"/>
  176. </xsl:call-template>
  177. </xsl:if>
  178. </xsl:template>
  179. </xsl:stylesheet>