xs-restriction-pattern.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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:ogc="http://www.opengis.net/ogc"
  5. xmlns:system_cache__appinfo="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd"
  6. exclude-result-prefixes="xs"
  7. version="2.0">
  8. <xsl:import href="../escaped_html_to_xml.xsl"/>
  9. <xsl:param name="ogc:debug"/>
  10. <xsl:variable name="ogc:pattern.debug" select="'((^(?!(BN)|(ND)).+$)|(.+(?&lt;!(BN)|(ND))$))'"/> <!-- ((^(?!(BN)|(ND)).+$)|(.+(?&lt;!(BN)|(ND))$)) -->
  11. <xsl:function name="ogc:translate_pattern_to_string">
  12. <xsl:param name="ogc:pattern"/> <!-- to convert ? ^ and ! signs to chars -->
  13. <xsl:variable name="EXC" select="'!'"/>
  14. <xsl:value-of select=" replace( replace(replace( replace( replace( replace( replace(replace(replace($ogc:pattern,'&lt;','_LT_'),'\(','&lt;_BRA_&gt;'),'\)','&lt;/_BRA_&gt;') ,'\?','_QM_' ),'\^','_EXP_' ),'\$','_DOL_' ),'\+','_PLUS_'), '!','_EXC_' ),'\|','_PIP_' ) "/>
  15. </xsl:function>
  16. <xsl:template name="ogc:main">
  17. <!-- debug -->
  18. <ogc:main>
  19. <xsl:message>#15 testing for $ogc:pattern=<xsl:value-of select="$ogc:pattern.debug"/>;</xsl:message>
  20. <xsl:variable name="ogc:pattern.escaped" select="ogc:translate_pattern_to_string($ogc:pattern.debug)"/>
  21. <xsl:variable name="system_cache__appinfo:escaped_html_to_xml" select="system_cache__appinfo:escaped_html_to_xml($ogc:pattern.escaped)"/>
  22. <system_cache__appinfo:escaped_html_to_xml>
  23. <xsl:copy-of select="$system_cache__appinfo:escaped_html_to_xml"></xsl:copy-of>
  24. </system_cache__appinfo:escaped_html_to_xml>
  25. <xsl:apply-templates select="$system_cache__appinfo:escaped_html_to_xml" mode="ogc:translate_pattern_to_string">
  26. <xsl:with-param name="name" select="'I_OPER'"/>
  27. </xsl:apply-templates>
  28. </ogc:main>
  29. </xsl:template>
  30. <xsl:template mode="ogc:translate_pattern_to_string" match="pattern" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  31. <xsl:param name="name" required="yes"/>
  32. <xsl:variable name="system_cache__appinfo:escaped_html_to_xml" select="system_cache__appinfo:escaped_html_to_xml(ogc:translate_pattern_to_string(@value))"/>
  33. <xsl:if test="number($ogc:debug) &gt; 3"><xsl:message>#45 ogc:translate_pattern_to_string matched pattern count($system_cache__appinfo:escaped_html_to_xml(<xsl:value-of select="count($system_cache__appinfo:escaped_html_to_xml//*)"/>)) at @id=<xsl:value-of select="@id"/>; @value=<xsl:value-of select="@value"/>; </xsl:message></xsl:if>
  34. <xsl:apply-templates mode="ogc:translate_pattern_to_string" select="$system_cache__appinfo:escaped_html_to_xml">
  35. <xsl:with-param name="name" select="$name"/>
  36. </xsl:apply-templates>
  37. <!-- to create ogc filter from input like this ((^(?!(BN)|(ND)).+$)|(.+(?&lt;!(BN)|(ND))$)) -->
  38. </xsl:template>
  39. <xsl:template mode="ogc:translate_pattern_to_string ogc:translate_pattern_to_string.singleNegation" match="text()"/>
  40. <xsl:template mode="ogc:translate_pattern_to_string" match="_BRA_[_BRA_ and not(text()='_QM__EXC_') and not( text()='_PIP_')]">
  41. <xsl:param name="name" required="yes"/>
  42. <xsl:if test="number($ogc:debug) &gt; 3">
  43. <xsl:comment>#47 match="_BRA_[_BRA_]" text()=<xsl:value-of select="text()"/>; <xsl:for-each select="./text()">[<xsl:value-of select="position()"/>]=<xsl:value-of select="."/>; </xsl:for-each></xsl:comment>
  44. <xsl:message>#47 match="_BRA_[_BRA_]" text()=<xsl:value-of select="text()"/>; <xsl:for-each select="./text()">[<xsl:value-of select="position()"/>]=<xsl:value-of select="."/>; </xsl:for-each></xsl:message>
  45. </xsl:if>
  46. <xsl:apply-templates mode="ogc:translate_pattern_to_string">
  47. <xsl:with-param name="text" select="text()"/>
  48. <xsl:with-param name="name" select="$name"/>
  49. </xsl:apply-templates>
  50. </xsl:template>
  51. <xsl:template mode="ogc:translate_pattern_to_string" match="_BRA_[ text()='_PIP_' and _BRA_/text()='_EXP_' and _BRA_/text()='._PLUS__DOL_' and _BRA_/text()='._PLUS_' and _BRA_/text()='_DOL_' ]" priority="9"> <!-- -->
  52. <xsl:param name="name" required="yes"/>
  53. <ogc:And>
  54. <xsl:if test="number($ogc:debug) &gt; 3">
  55. <xsl:comment>#73-A -
  56. wariant dla pojedynczej negacji aby nie wystepowala wartosc z enum - np I_OPER!= BN or ND
  57. childs _QM__EXC + _QM__LT__EXC - oznacza negacje wystapienia jednego elementu - brac jedno match="_BRA_[_BRA_ and not(text()='_QM__EXC_') and text()='_PIP_']" text()=<xsl:value-of select="text()"/>; <xsl:for-each select="./text()">[<xsl:value-of select="position()"/>]=<xsl:value-of select="."/>; </xsl:for-each></xsl:comment>
  58. <xsl:comment> _BRA_/text()=;<xsl:for-each select="_BRA_"> = [<xsl:value-of select="position()"/>]=<xsl:value-of select="text()"/></xsl:for-each></xsl:comment>
  59. <xsl:message> _BRA_/text()=;<xsl:for-each select="_BRA_"> = [<xsl:value-of select="position()"/>]=<xsl:value-of select="text()"/></xsl:for-each></xsl:message>
  60. </xsl:if>
  61. <xsl:apply-templates mode="ogc:translate_pattern_to_string.singleNegation" >
  62. <xsl:with-param name="text" select="text()"/>
  63. <xsl:with-param name="name" select="$name"/>
  64. </xsl:apply-templates>
  65. </ogc:And>
  66. </xsl:template>
  67. <xsl:template mode="ogc:translate_pattern_to_string" match="_BRA_[ text()='._PLUS__DOL_']">
  68. <xsl:param name="name" required="yes"/>
  69. <xsl:if test="number($ogc:debug) &gt; 3">
  70. <xsl:comment>
  71. #84-A* Bypased element <xsl:value-of select="name()"/> ; text()=<xsl:value-of select="text()"/></xsl:comment>
  72. <xsl:message>
  73. #84-A* Bypased element <xsl:value-of select="name()"/> ; text()=<xsl:value-of select="text()"/></xsl:message>
  74. </xsl:if>
  75. <xsl:apply-templates mode="#current">
  76. <xsl:with-param name="name" select="$name"/>
  77. </xsl:apply-templates>
  78. </xsl:template>
  79. <xsl:template mode="ogc:translate_pattern_to_string.singleNegation" match="*">
  80. <xsl:param name="name" required="yes"/>
  81. <xsl:if test="number($ogc:debug) &gt; 3">
  82. <xsl:comment>
  83. #84-B* Bypased element <xsl:value-of select="name()"/> ; text()=<xsl:value-of select="text()"/></xsl:comment>
  84. <xsl:message>
  85. #84-B* Bypased element <xsl:value-of select="name()"/> ; text()=<xsl:value-of select="text()"/></xsl:message>
  86. </xsl:if>
  87. <xsl:apply-templates mode="#current" select="_BRA_[1]">
  88. <xsl:with-param name="name" select="$name"/>
  89. </xsl:apply-templates>
  90. </xsl:template>
  91. <xsl:template mode="ogc:translate_pattern_to_string" match="_BRA_[_BRA_ and not(text()='_QM__EXC_') and text()='_PIP_' and not(text()='_QM__LT__EXC_')]" >
  92. <xsl:param name="name" required="yes"/>
  93. <ogc:Or>
  94. <xsl:if test="number($ogc:debug) &gt; 3">
  95. <xsl:comment>#73 match="_BRA_[_BRA_ and not(text()='_QM__EXC_') and text()='_PIP_']" text()=<xsl:value-of select="text()"/>; <xsl:for-each select="./text()">[<xsl:value-of select="position()"/>]=<xsl:value-of select="."/>; </xsl:for-each></xsl:comment>
  96. <xsl:message>#73 match="_BRA_[_BRA_ and not(text()='_QM__EXC_') and text()='_PIP_']" text()=<xsl:value-of select="text()"/>; <xsl:for-each select="./text()">[<xsl:value-of select="position()"/>]=<xsl:value-of select="."/>; </xsl:for-each></xsl:message>
  97. <xsl:comment>
  98. text()=<xsl:value-of select="text()"/>
  99. _BRA_/text()=; <xsl:value-of select="_BRA_/text()"/> <xsl:for-each select="_BRA_/text()"> = [<xsl:value-of select="position()"/>]=<xsl:value-of select="."/></xsl:for-each></xsl:comment>
  100. </xsl:if>
  101. <xsl:apply-templates mode="ogc:translate_pattern_to_string">
  102. <xsl:with-param name="text" select="text()"/>
  103. <xsl:with-param name="name" select="$name"/>
  104. </xsl:apply-templates>
  105. </ogc:Or>
  106. </xsl:template>
  107. <xsl:template mode="ogc:translate_pattern_to_string" match="_BRA_[_BRA_ and text()='_QM__EXC_' and text()='_PIP']">
  108. <xsl:param name="name" required="yes"/>
  109. <ogc:Or>
  110. <xsl:comment>#71 match="_BRA_[_BRA_ and text()='_PIP']"</xsl:comment>
  111. <xsl:apply-templates mode="ogc:translate_pattern_to_string">
  112. <xsl:with-param name="text" select="text()"/>
  113. <xsl:with-param name="name" select="$name"/>
  114. </xsl:apply-templates>
  115. </ogc:Or>
  116. </xsl:template>
  117. <xsl:template mode="ogc:translate_pattern_to_string" match="_BRA_[ text()='_QM__EXC_' or text()='_QM__LT__EXC_']">
  118. <xsl:param name="name" required="yes"/>
  119. <xsl:param name="text"/>
  120. <ogc:Not>
  121. <xsl:if test="number($ogc:debug) &gt; 3"><xsl:comment>#95-A match="_BRA_[ text()='_QM__EXC_' or text()='_QM__LT__EXC_']" - w zasadzie jak jest _QM__LT__EXC_ oraz _QM__EXC_ oznacza to zwykla negacje aby cos nie bylo w tekscie, wiec mozna olac na wstepie dwa dzieci i wziadc jedno
  122. text()=<xsl:value-of select="text()"/>;
  123. </xsl:comment>
  124. </xsl:if>
  125. <!--<parent_text><xsl:value-of select="$text"/> <xsl:for-each select="$text">[<xsl:value-of select="position()"/>]=<xsl:value-of select="."/>; </xsl:for-each></parent_text>-->
  126. <!--<current><xsl:copy-of select="*"></xsl:copy-of></current>-->
  127. <xsl:apply-templates mode="#current">
  128. <xsl:with-param name="text" select="text()"/>
  129. <xsl:with-param name="name" select="$name"/>
  130. </xsl:apply-templates>
  131. </ogc:Not>
  132. </xsl:template>
  133. <xsl:template mode="ogc:translate_pattern_to_string.singleNegation" match="_BRA_[ text()='_QM__EXC_']">
  134. <xsl:message>#144 bypassed for once filter</xsl:message>
  135. </xsl:template>
  136. <xsl:template mode="ogc:translate_pattern_to_string.singleNegation" match="_BRA_[ text()='_QM__LT__EXC_']">
  137. <xsl:param name="name" required="yes"/>
  138. <xsl:param name="text"/>
  139. <ogc:Not>
  140. <xsl:if test="number($ogc:debug) &gt; 3">
  141. <xsl:comment>#95-B match="_BRA_[ text()='_QM__EXC_' or text()='_QM__LT__EXC_']" - w zasadzie jak jest _QM__LT__EXC_ oraz _QM__EXC_ oznacza to zwykla negacje aby cos nie bylo w tekscie, wiec mozna olac na wstepie dwa dzieci i wziadc jedno
  142. text()=<xsl:value-of select="text()"/>;
  143. </xsl:comment>
  144. </xsl:if>
  145. <!--<parent_text><xsl:value-of select="$text"/> <xsl:for-each select="$text">[<xsl:value-of select="position()"/>]=<xsl:value-of select="."/>; </xsl:for-each></parent_text>-->
  146. <!--<current><xsl:copy-of select="*"></xsl:copy-of></current>-->
  147. <xsl:apply-templates mode="#current">
  148. <xsl:with-param name="text" select="text()"/>
  149. <xsl:with-param name="name" select="$name"/>
  150. </xsl:apply-templates>
  151. </ogc:Not>
  152. </xsl:template>
  153. <xsl:template mode="ogc:translate_pattern_to_string ogc:translate_pattern_to_string.singleNegation" match="_BRA_[not(_BRA_) and text()]">
  154. <xsl:param name="name" required="yes"/>
  155. <ogc:PropertyIsEqualTo>
  156. <xsl:if test="number($ogc:debug) &gt; 3">
  157. <xsl:comment>
  158. #137 matched text()=<xsl:value-of select="text()"/>;
  159. </xsl:comment>
  160. </xsl:if>
  161. <ogc:PropertyName><xsl:value-of select="$name"/></ogc:PropertyName>
  162. <ogc:Literal><xsl:value-of select="text()"/></ogc:Literal>
  163. </ogc:PropertyIsEqualTo>
  164. </xsl:template>
  165. </xsl:stylesheet>