escaped_html_to_xml.xsl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:system_cache__appinfo="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd"
  5. exclude-result-prefixes="xs system_cache__appinfo"
  6. version="2.0">
  7. <xsl:output indent="yes"/>
  8. <xsl:function name="system_cache__appinfo:escaped_html_to_xml">
  9. <xsl:param name="html" />
  10. <xsl:call-template name="system_cache__appinfo:escaped_html_to_xml">
  11. <xsl:with-param name="html" select="$html"/>
  12. </xsl:call-template>
  13. </xsl:function>
  14. <xsl:function name="system_cache__appinfo:enter_surround_to">
  15. <xsl:param name="text" />
  16. <xsl:param name="surround_with" />
  17. <xsl:choose>
  18. <xsl:when test=" contains( $text,'&#10;')">
  19. <xsl:for-each select="tokenize($text ,'&#10;')">
  20. <xsl:element name="{$surround_with}"><!-- to jest przetwarzane jak jest tekst lamany -->
  21. <xsl:value-of select="."/>
  22. </xsl:element>
  23. </xsl:for-each>
  24. </xsl:when>
  25. <xsl:otherwise>
  26. <xsl:copy-of select="$text"/>
  27. </xsl:otherwise>
  28. </xsl:choose>
  29. </xsl:function>
  30. <xsl:template name="escaped_html_to_xml_and_surrounded_enter">
  31. <xsl:param name="html" required="yes"/>
  32. <xsl:param name="enter_surround_to" select="'br'"/>
  33. <xsl:variable name="element_html" select="$html/name()"/>
  34. <xsl:variable name="enter_surround_to_get" select="system_cache__appinfo:enter_surround_to($html,$enter_surround_to)"/>
  35. <xsl:variable name="out">
  36. <xsl:for-each select="$enter_surround_to_get">
  37. <xsl:element name="{name()}">
  38. <xsl:copy-of select="system_cache__appinfo:escaped_html_to_xml(.)"/>
  39. </xsl:element>
  40. </xsl:for-each>
  41. </xsl:variable>
  42. <xsl:choose>
  43. <xsl:when test=" count($enter_surround_to_get) &gt;1 ">
  44. <xsl:copy-of select="$out/*" copy-namespaces="no"/>
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <xsl:copy-of select="system_cache__appinfo:escaped_html_to_xml($html)"></xsl:copy-of>
  48. </xsl:otherwise>
  49. </xsl:choose>
  50. </xsl:template>
  51. <xsl:template name="system_cache__appinfo:escaped_html_to_xml">
  52. <xsl:param name="html"/>
  53. <xsl:param name="debug" select="false()"/>
  54. <xsl:param name="loopno" select="1"/>
  55. <xsl:variable name="anal_out">
  56. <anal_out>
  57. <xsl:for-each select=" tokenize($html,'&lt;') ">
  58. <xsl:variable name="lt_pos" select="position()"/>
  59. <lt>
  60. <xsl:attribute name="lt_pos" select="position()"/>
  61. <!--<xsl:value-of select="."/>-->
  62. <xsl:for-each select="tokenize(.,'&gt;')">
  63. <gt>
  64. <xsl:attribute name="gtnum" select="position()"/>
  65. <!--<xsl:attribute name="lt_pos" select="$lt_pos"/>-->
  66. <xsl:choose>
  67. <xsl:when test="$lt_pos=1 and position()=1">
  68. <xsl:attribute name="tag_place" select="'before_tag'"/>
  69. </xsl:when>
  70. <xsl:when test="$lt_pos=2 and position()=1">
  71. <xsl:attribute name="tag_place" select="'first_tag'"/>
  72. </xsl:when>
  73. </xsl:choose>
  74. <xsl:choose>
  75. <xsl:when test="position()=1 and $lt_pos&gt;1">
  76. <xsl:attribute name="is_tag" select="true()"/>
  77. </xsl:when>
  78. <xsl:otherwise><xsl:attribute name="is_string" select="true()"/></xsl:otherwise>
  79. </xsl:choose>
  80. <xsl:choose>
  81. <xsl:when test=" contains(.,'/') and position()=1 and $lt_pos>1"><xsl:attribute name="closing" select="true()"/></xsl:when>
  82. <xsl:when test=" not(contains(.,'/')) and position()=1 and $lt_pos>1"><xsl:attribute name="closing" select="false()"/></xsl:when>
  83. <!--<xsl:otherwise><xsl:attribute name="closing" select="false()"/></xsl:otherwise>-->
  84. </xsl:choose>
  85. <xsl:choose>
  86. <xsl:when test="position()=1 and $lt_pos&gt;1 and not(contains(.,'/')) and contains(.,' ')">
  87. <xsl:variable name="attributes">
  88. <xsl:for-each select="tokenize(.,' ')">
  89. <el><xsl:value-of select="."/></el>
  90. </xsl:for-each>
  91. </xsl:variable>
  92. <xsl:attribute name="attributes" select="$attributes/el[position()&gt;1]"/>
  93. <xsl:copy-of select="$attributes/el[position()=1]/text()"/>
  94. </xsl:when>
  95. <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  96. </xsl:choose>
  97. <!--<xsl:value-of select="."/>-->
  98. </gt>
  99. </xsl:for-each>
  100. </lt>
  101. </xsl:for-each>
  102. </anal_out>
  103. </xsl:variable>
  104. <!--<analyse>
  105. <before_tag><xsl:value-of select="$anal_out/anal_out/lt[@ltnum=1]/gt[@gtnum=1]/text()"/></before_tag>
  106. <first_tag><xsl:value-of select="$anal_out/anal_out/lt[@ltnum=2]/gt[@gtnum=1]/text()"/></first_tag>
  107. <closing_tag></closing_tag>
  108. <after_closing_tag></after_closing_tag>
  109. </analyse>-->
  110. <!--<xsl:copy-of select="$anal_out"/>-->
  111. <xsl:variable name="anal_num">
  112. <anal_num>
  113. <xsl:for-each select="$anal_out/anal_out/lt/gt">
  114. <gt><xsl:attribute name="pos" select="position()"/>
  115. <xsl:copy-of select="@attributes"/>
  116. <xsl:choose>
  117. <xsl:when test="@is_string=true()">
  118. <xsl:attribute name="level" select="0"/>
  119. <xsl:value-of select="text()"/></xsl:when>
  120. <xsl:when test="@is_tag=true() and @closing=false()">
  121. <xsl:attribute name="level" select="1"/>
  122. <xsl:choose>
  123. <xsl:when test=" position()=1">
  124. <xsl:attribute name="new_gr" select="2"/>
  125. </xsl:when>
  126. <xsl:otherwise>
  127. <xsl:attribute name="new_gr" select="1"/>
  128. </xsl:otherwise>
  129. </xsl:choose>
  130. <xsl:attribute name="element" select="text()"/>
  131. </xsl:when>
  132. <xsl:when test="@is_tag=true() and @closing=true()">
  133. <xsl:attribute name="level" select="-1"/>
  134. <xsl:attribute name="element" select="text()"/>
  135. </xsl:when>
  136. </xsl:choose>
  137. </gt>
  138. </xsl:for-each>
  139. </anal_num>
  140. </xsl:variable>
  141. <!--<xsl:copy-of select="$anal_num"/>-->
  142. <xsl:variable name="anal_num1">
  143. <anal_num1>
  144. <xsl:for-each select="$anal_num/anal_num/gt">
  145. <gt>
  146. <xsl:copy-of select="@*"/>
  147. <xsl:choose>
  148. <xsl:when test="@level=0 and $anal_num/anal_num/gt[number(@pos)= number(current()/@pos)-1]/@level=1"><xsl:attribute name="level" select="1"/></xsl:when><!-- and $anal_num/anal_num/gt[@pos=current()/@pos-1]/@level= -->
  149. <xsl:when test="@level=0 and $anal_num/anal_num/gt[number(@pos)= number(current()/@pos)-1]/@level=-1"><xsl:attribute name="level" select="-1"/></xsl:when>
  150. <xsl:otherwise><xsl:attribute name="level" select="@level"/></xsl:otherwise>
  151. </xsl:choose>
  152. <xsl:value-of select="text()"/>
  153. </gt>
  154. </xsl:for-each>
  155. </anal_num1>
  156. </xsl:variable>
  157. <!--<xsl:copy-of select="$anal_num1"/>-->
  158. <xsl:variable name="anal_num_anal">
  159. <anal_num_anal>
  160. <xsl:for-each select="$anal_num1/anal_num1/gt">
  161. <gt>
  162. <xsl:variable name="cur_pos" select="@pos"/>
  163. <!--<xsl:attribute name="what_sum" select="concat('sum($anal_num/anal_num/gt[@pos&lt;=',$cur_pos,']/@level')" />-->
  164. <xsl:choose>
  165. <xsl:when test="sum($anal_num1/anal_num1/gt[number(@pos)&lt;= number($cur_pos) ]/@level)&lt;0">
  166. <xsl:attribute name="sum_cur" select="1"/>
  167. <xsl:attribute name="sum_cur_293" select="true()"/>
  168. </xsl:when>
  169. <!--<xsl:when test="@level=-1">
  170. <xsl:attribute name="sum_cur" select="sum($anal_num1/anal_num1/gt[number(@pos)&lt;number($cur_pos) ]/@level)+1"/>
  171. </xsl:when>-->
  172. <xsl:otherwise><xsl:attribute name="sum_cur" select="sum($anal_num1/anal_num1/gt[number(@pos)&lt;= number($cur_pos) ]/@level)+1"/></xsl:otherwise>
  173. </xsl:choose>
  174. <xsl:copy-of select="@*"/>
  175. <xsl:value-of select="text()"/>
  176. <!--<copy>
  177. <xsl:copy-of select="$anal_num/anal_num/gt[ number(@pos)&lt;= number($cur_pos) ]"/>
  178. </copy>-->
  179. </gt>
  180. </xsl:for-each>
  181. </anal_num_anal>
  182. </xsl:variable>
  183. <!--<xsl:copy-of select="$anal_num_anal"/>-->
  184. <xsl:for-each select="$anal_num_anal/anal_num_anal/gt[@sum_cur=1]"><!-- text outside of first tag -->
  185. <xsl:variable name="min_pos_sum_cur_1" select="min($anal_num_anal/anal_num_anal/gt[@sum_cur=1 and number(@pos)&gt;number(current()/@pos)]/@pos)"/>
  186. <xsl:value-of select="text()"/>
  187. <xsl:for-each select="$anal_num_anal/anal_num_anal/gt[@sum_cur=2 and number(@pos)&gt;number(current()/@pos) and number(@pos)&lt;number($min_pos_sum_cur_1) and @level=1 ]"><!-- first level tags -->
  188. <xsl:element name="{@element}">
  189. <xsl:choose>
  190. <xsl:when test="@attributes">
  191. <xsl:variable name="attributes">
  192. <xsl:for-each select="tokenize(@attributes,' ')">
  193. <e300><xsl:attribute name="val" select="."/>
  194. <xsl:for-each select="tokenize(.,'=&quot;')">
  195. <e302><xsl:attribute name="val" select="."/>
  196. <!--<xsl:attribute name="{.}" select="true()"/>-->
  197. <xsl:for-each select="tokenize(.,'&quot;')">
  198. <e307>
  199. <xsl:attribute name="val" select="."/>
  200. </e307>
  201. </xsl:for-each>
  202. </e302>
  203. </xsl:for-each>
  204. </e300>
  205. </xsl:for-each>
  206. </xsl:variable>
  207. <xsl:for-each select="$attributes/e300">
  208. <xsl:attribute name="{e302[1]/@val}" select="e302[2]/e307[1]/@val"/>
  209. </xsl:for-each>
  210. <!--<xsl:copy-of select="$attributes"/>-->
  211. </xsl:when>
  212. </xsl:choose>
  213. <xsl:variable name="html2">
  214. <xsl:for-each select="$anal_num_anal/anal_num_anal/gt[@sum_cur&gt;2 and number(@pos)&gt;number(current()/@pos) and number(@pos)&lt;number($min_pos_sum_cur_1) ]"><!-- text of 1 level tags -->
  215. <xsl:choose>
  216. <xsl:when test="@element">&lt;<xsl:value-of select="@element"/>&gt;</xsl:when>
  217. <xsl:otherwise><xsl:copy-of select="text()"/></xsl:otherwise>
  218. </xsl:choose>
  219. </xsl:for-each>
  220. </xsl:variable>
  221. <xsl:call-template name="system_cache__appinfo:escaped_html_to_xml">
  222. <xsl:with-param name="html" select="$html2"/>
  223. </xsl:call-template>
  224. </xsl:element>
  225. </xsl:for-each>
  226. </xsl:for-each>
  227. <xsl:choose><!-- warunek xxxx<br>yyyy nie zwraca - daje IFa -->
  228. <xsl:when test=" count($anal_num1/anal_num1/gt) = 3
  229. and $anal_num_anal/anal_num_anal/gt[1][ @sum_cur='1' and @pos='1' and @level='0']
  230. and $anal_num_anal/anal_num_anal/gt[2][ @sum_cur='2' and @pos='2' and @level='1' and @new_gr='1']
  231. and $anal_num_anal/anal_num_anal/gt[3][ @sum_cur='3' and @pos='3' and @level='1']
  232. "><xsl:value-of select="' '"/><xsl:value-of select="$anal_num_anal/anal_num_anal/gt[3]/text()"/></xsl:when>
  233. </xsl:choose>
  234. </xsl:template>
  235. </xsl:stylesheet>