escaped_html_to_xml.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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:template name="system_cache__appinfo:escaped_html_to_xml">
  9. <xsl:param name="html"/>
  10. <xsl:param name="debug" select="false()"/>
  11. <xsl:param name="loopno" select="1"/>
  12. <xsl:variable name="anal_out">
  13. <anal_out>
  14. <xsl:for-each select=" tokenize($html,'&lt;') ">
  15. <xsl:variable name="lt_pos" select="position()"/>
  16. <lt>
  17. <xsl:attribute name="lt_pos" select="position()"/>
  18. <!--<xsl:value-of select="."/>-->
  19. <xsl:for-each select="tokenize(.,'&gt;')">
  20. <gt>
  21. <xsl:attribute name="gtnum" select="position()"/>
  22. <!--<xsl:attribute name="lt_pos" select="$lt_pos"/>-->
  23. <xsl:choose>
  24. <xsl:when test="$lt_pos=1 and position()=1">
  25. <xsl:attribute name="tag_place" select="'before_tag'"/>
  26. </xsl:when>
  27. <xsl:when test="$lt_pos=2 and position()=1">
  28. <xsl:attribute name="tag_place" select="'first_tag'"/>
  29. </xsl:when>
  30. </xsl:choose>
  31. <xsl:choose>
  32. <xsl:when test="position()=1 and $lt_pos&gt;1">
  33. <xsl:attribute name="is_tag" select="true()"/>
  34. </xsl:when>
  35. <xsl:otherwise><xsl:attribute name="is_string" select="true()"/></xsl:otherwise>
  36. </xsl:choose>
  37. <xsl:choose>
  38. <xsl:when test=" contains(.,'/') and position()=1 and $lt_pos>1"><xsl:attribute name="closing" select="true()"/></xsl:when>
  39. <xsl:when test=" not(contains(.,'/')) and position()=1 and $lt_pos>1"><xsl:attribute name="closing" select="false()"/></xsl:when>
  40. <!--<xsl:otherwise><xsl:attribute name="closing" select="false()"/></xsl:otherwise>-->
  41. </xsl:choose>
  42. <xsl:choose>
  43. <xsl:when test="position()=1 and $lt_pos&gt;1 and not(contains(.,'/')) and contains(.,' ')">
  44. <xsl:variable name="attributes">
  45. <xsl:for-each select="tokenize(.,' ')">
  46. <el><xsl:value-of select="."/></el>
  47. </xsl:for-each>
  48. </xsl:variable>
  49. <xsl:attribute name="attributes" select="$attributes/el[position()&gt;1]"/>
  50. <xsl:copy-of select="$attributes/el[position()=1]/text()"/>
  51. </xsl:when>
  52. <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  53. </xsl:choose>
  54. <!--<xsl:value-of select="."/>-->
  55. </gt>
  56. </xsl:for-each>
  57. </lt>
  58. </xsl:for-each>
  59. </anal_out>
  60. </xsl:variable>
  61. <!--<analyse>
  62. <before_tag><xsl:value-of select="$anal_out/anal_out/lt[@ltnum=1]/gt[@gtnum=1]/text()"/></before_tag>
  63. <first_tag><xsl:value-of select="$anal_out/anal_out/lt[@ltnum=2]/gt[@gtnum=1]/text()"/></first_tag>
  64. <closing_tag></closing_tag>
  65. <after_closing_tag></after_closing_tag>
  66. </analyse>-->
  67. <!--<xsl:copy-of select="$anal_out"/>-->
  68. <xsl:variable name="anal_num">
  69. <anal_num>
  70. <xsl:for-each select="$anal_out/anal_out/lt/gt">
  71. <gt><xsl:attribute name="pos" select="position()"/>
  72. <xsl:copy-of select="@attributes"/>
  73. <xsl:choose>
  74. <xsl:when test="@is_string=true()">
  75. <xsl:attribute name="level" select="0"/>
  76. <xsl:value-of select="text()"/></xsl:when>
  77. <xsl:when test="@is_tag=true() and @closing=false()">
  78. <xsl:attribute name="level" select="1"/>
  79. <xsl:choose>
  80. <xsl:when test=" position()=1">
  81. <xsl:attribute name="new_gr" select="2"/>
  82. </xsl:when>
  83. <xsl:otherwise>
  84. <xsl:attribute name="new_gr" select="1"/>
  85. </xsl:otherwise>
  86. </xsl:choose>
  87. <xsl:attribute name="element" select="text()"/>
  88. </xsl:when>
  89. <xsl:when test="@is_tag=true() and @closing=true()">
  90. <xsl:attribute name="level" select="-1"/>
  91. <xsl:attribute name="element" select="text()"/>
  92. </xsl:when>
  93. </xsl:choose>
  94. </gt>
  95. </xsl:for-each>
  96. </anal_num>
  97. </xsl:variable>
  98. <!--<xsl:copy-of select="$anal_num"/>-->
  99. <xsl:variable name="anal_num1">
  100. <anal_num1>
  101. <xsl:for-each select="$anal_num/anal_num/gt">
  102. <gt>
  103. <xsl:copy-of select="@*"/>
  104. <xsl:choose>
  105. <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= -->
  106. <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>
  107. <xsl:otherwise><xsl:attribute name="level" select="@level"/></xsl:otherwise>
  108. </xsl:choose>
  109. <xsl:value-of select="text()"/>
  110. </gt>
  111. </xsl:for-each>
  112. </anal_num1>
  113. </xsl:variable>
  114. <!--<xsl:copy-of select="$anal_num1"/>-->
  115. <xsl:variable name="anal_num_anal">
  116. <anal_num_anal>
  117. <xsl:for-each select="$anal_num1/anal_num1/gt">
  118. <gt>
  119. <xsl:variable name="cur_pos" select="@pos"/>
  120. <!--<xsl:attribute name="what_sum" select="concat('sum($anal_num/anal_num/gt[@pos&lt;=',$cur_pos,']/@level')" />-->
  121. <xsl:choose>
  122. <xsl:when test="sum($anal_num1/anal_num1/gt[number(@pos)&lt;= number($cur_pos) ]/@level)&lt;0">
  123. <xsl:attribute name="sum_cur" select="1"/>
  124. <xsl:attribute name="sum_cur_293" select="true()"/>
  125. </xsl:when>
  126. <!--<xsl:when test="@level=-1">
  127. <xsl:attribute name="sum_cur" select="sum($anal_num1/anal_num1/gt[number(@pos)&lt;number($cur_pos) ]/@level)+1"/>
  128. </xsl:when>-->
  129. <xsl:otherwise><xsl:attribute name="sum_cur" select="sum($anal_num1/anal_num1/gt[number(@pos)&lt;= number($cur_pos) ]/@level)+1"/></xsl:otherwise>
  130. </xsl:choose>
  131. <xsl:copy-of select="@*"/>
  132. <xsl:value-of select="text()"/>
  133. <!--<copy>
  134. <xsl:copy-of select="$anal_num/anal_num/gt[ number(@pos)&lt;= number($cur_pos) ]"/>
  135. </copy>-->
  136. </gt>
  137. </xsl:for-each>
  138. </anal_num_anal>
  139. </xsl:variable>
  140. <!--<xsl:copy-of select="$anal_num_anal"/>-->
  141. <xsl:for-each select="$anal_num_anal/anal_num_anal/gt[@sum_cur=1]"><!-- text outside of first tag -->
  142. <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)"/>
  143. <xsl:value-of select="text()"/>
  144. <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 -->
  145. <xsl:element name="{@element}">
  146. <xsl:choose>
  147. <xsl:when test="@attributes">
  148. <xsl:variable name="attributes">
  149. <xsl:for-each select="tokenize(@attributes,' ')">
  150. <e300><xsl:attribute name="val" select="."/>
  151. <xsl:for-each select="tokenize(.,'=&quot;')">
  152. <e302><xsl:attribute name="val" select="."/>
  153. <!--<xsl:attribute name="{.}" select="true()"/>-->
  154. <xsl:for-each select="tokenize(.,'&quot;')">
  155. <e307>
  156. <xsl:attribute name="val" select="."/>
  157. </e307>
  158. </xsl:for-each>
  159. </e302>
  160. </xsl:for-each>
  161. </e300>
  162. </xsl:for-each>
  163. </xsl:variable>
  164. <xsl:for-each select="$attributes/e300">
  165. <xsl:attribute name="{e302[1]/@val}" select="e302[2]/e307[1]/@val"/>
  166. </xsl:for-each>
  167. <!--<xsl:copy-of select="$attributes"/>-->
  168. </xsl:when>
  169. </xsl:choose>
  170. <xsl:variable name="html2">
  171. <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 -->
  172. <xsl:choose>
  173. <xsl:when test="@element">&lt;<xsl:value-of select="@element"/>&gt;</xsl:when>
  174. <xsl:otherwise><xsl:copy-of select="text()"/></xsl:otherwise>
  175. </xsl:choose>
  176. </xsl:for-each>
  177. </xsl:variable>
  178. <xsl:call-template name="system_cache__appinfo:escaped_html_to_xml">
  179. <xsl:with-param name="html" select="$html2"/>
  180. </xsl:call-template>
  181. </xsl:element>
  182. </xsl:for-each>
  183. </xsl:for-each>
  184. </xsl:template>
  185. </xsl:stylesheet>