PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/library/xslt/src/style/xm_xslt_literal_result_element.e

http://github.com/gobo-eiffel/gobo
Specman e | 645 lines | 535 code | 63 blank | 47 comment | 51 complexity | 90c3e4fc9a3472b98715b1bfbdb4e58b MD5 | raw file
  1. note
  2. description:
  3. "Literal result elements"
  4. library: "Gobo Eiffel XSLT Library"
  5. copyright: "Copyright (c) 2004-2018, Colin Adams and others"
  6. license: "MIT License"
  7. date: "$Date$"
  8. revision: "$Revision$"
  9. class XM_XSLT_LITERAL_RESULT_ELEMENT
  10. inherit
  11. XM_XSLT_STYLE_ELEMENT
  12. redefine
  13. validate, validate_children, may_contain_sequence_constructor, trace_property, construct_type, make_style_element
  14. end
  15. XM_XSLT_TRACE_CONSTANTS
  16. create {XM_XSLT_NODE_FACTORY}
  17. make_style_element
  18. feature {NONE} -- Initialization
  19. make_style_element (an_error_listener: XM_XSLT_ERROR_LISTENER; a_document: XM_XPATH_TREE_DOCUMENT; a_parent: detachable XM_XPATH_TREE_COMPOSITE_NODE;
  20. an_attribute_collection: detachable XM_XPATH_ATTRIBUTE_COLLECTION; a_namespace_list: detachable DS_ARRAYED_LIST [INTEGER];
  21. a_name_code: INTEGER; a_sequence_number: INTEGER; a_configuration: like configuration)
  22. -- Establish invariant.
  23. do
  24. is_instruction := True
  25. is_inherit_namespaces := True
  26. Precursor (an_error_listener, a_document, a_parent, an_attribute_collection, a_namespace_list, a_name_code, a_sequence_number, a_configuration)
  27. end
  28. feature -- Access
  29. is_inherit_namespaces: BOOLEAN
  30. -- Do we inherit namespaces?
  31. trace_property (an_expanded_name: STRING): STRING
  32. -- Value of trace-property
  33. do
  34. if STRING_.same_string (an_expanded_name, Gexslt_name_pseudo_attribute) then
  35. Result := shared_name_pool.display_name_from_name_code (name_code)
  36. else
  37. Result := Precursor (an_expanded_name)
  38. end
  39. end
  40. construct_type: INTEGER
  41. -- Type of construct being traced
  42. do
  43. Result := Literal_result_element
  44. end
  45. feature -- Status report
  46. may_contain_sequence_constructor: BOOLEAN
  47. -- Is `Current' allowed to contain a sequence constructor?
  48. do
  49. Result := True
  50. end
  51. feature -- Element change
  52. prepare_attributes
  53. -- Set the attribute list for the element.
  54. local
  55. an_index, a_name_code, a_uri_code, a_fingerprint: INTEGER
  56. an_inherit_namespaces_attribute: STRING
  57. an_error: XM_XPATH_ERROR_VALUE
  58. l_attribute_values: like attribute_values
  59. l_attribute_name_codes: like attribute_name_codes
  60. l_attribute_clean_flags: like attribute_clean_flags
  61. do
  62. create l_attribute_name_codes.make (number_of_attributes)
  63. attribute_name_codes := l_attribute_name_codes
  64. create l_attribute_values.make (number_of_attributes)
  65. l_attribute_values.set_equality_tester (expression_tester)
  66. attribute_values := l_attribute_values
  67. create l_attribute_clean_flags.make (number_of_attributes)
  68. attribute_clean_flags := l_attribute_clean_flags
  69. if number_of_attributes > 0 then
  70. from
  71. an_index := 1
  72. until
  73. any_compile_errors or else an_index > number_of_attributes
  74. loop
  75. a_name_code := attribute_name_code (an_index)
  76. a_uri_code := shared_name_pool.uri_code_from_name_code (a_name_code)
  77. if a_uri_code = Xslt_uri_code then
  78. a_fingerprint := shared_name_pool.fingerprint_from_name_code (a_name_code)
  79. if a_fingerprint = Xslt_use_attribute_sets_type_code then -- deal with this later
  80. elseif a_fingerprint = Xslt_use_when_type_code then -- already dealt with
  81. elseif a_fingerprint = Xslt_extension_element_prefixes_type_code then -- already dealt with
  82. elseif a_fingerprint = Xslt_exclude_result_prefixes_type_code then -- already dealt with
  83. elseif a_fingerprint = Xslt_version_type_code then -- already dealt with
  84. elseif a_fingerprint = Xslt_xpath_default_namespace_type_code then -- already dealt with
  85. elseif a_fingerprint = Xslt_default_collation_type_code then -- already dealt with
  86. elseif a_fingerprint = Xslt_type_type_code then -- deal with this later
  87. elseif a_fingerprint = Xslt_validation_type_code then -- deal with this later
  88. elseif a_fingerprint = Xslt_inherit_namespaces_type_code then
  89. an_inherit_namespaces_attribute := attribute_value_by_index (an_index)
  90. STRING_.left_adjust (an_inherit_namespaces_attribute)
  91. STRING_.right_adjust (an_inherit_namespaces_attribute)
  92. if STRING_.same_string (an_inherit_namespaces_attribute, "no") then
  93. is_inherit_namespaces := False
  94. elseif STRING_.same_string (an_inherit_namespaces_attribute, "yes") then
  95. is_inherit_namespaces := True
  96. else
  97. create an_error.make_from_string ("Value of xsl:inherit-namespaces must be 'yes' or 'no'", Xpath_errors_uri, "XTSE0020", Static_error)
  98. report_compile_error (an_error)
  99. end
  100. else
  101. create an_error.make_from_string (STRING_.concat ("Unknown XSL attribute ", shared_name_pool.display_name_from_name_code (a_name_code)), Xpath_errors_uri, "XTSE0805", Static_error)
  102. report_compile_error (an_error)
  103. end
  104. else
  105. l_attribute_name_codes.put_last (a_name_code)
  106. check precondition_static_context_not_void: attached static_context as l_static_context then
  107. generate_attribute_value_template (attribute_value_by_index (an_index), l_static_context)
  108. end
  109. check postcondition_of_generate_attribute_value_template: attached last_generated_expression as l_last_generated_expression then
  110. l_attribute_values.put_last (l_last_generated_expression)
  111. l_attribute_clean_flags.put_last (is_attribute_checked_clean (l_last_generated_expression))
  112. end
  113. end
  114. an_index := an_index + 1
  115. variant
  116. number_of_attributes + 1 - an_index
  117. end
  118. end
  119. attributes_prepared := True
  120. end
  121. validate
  122. -- Check that the stylesheet element is valid.
  123. local
  124. l_element_uri_code: INTEGER
  125. l_stylesheet: XM_XSLT_STYLESHEET
  126. do
  127. result_name_code := name_code
  128. l_element_uri_code := shared_name_pool.uri_code_from_name_code (result_name_code)
  129. if is_top_level then
  130. validate_top_level_element (l_element_uri_code)
  131. else
  132. check attached principal_stylesheet as l_principal_stylesheet then
  133. l_stylesheet := l_principal_stylesheet
  134. end
  135. -- Build the list of output namespace nodes
  136. if should_namespaces_be_omitted (l_element_uri_code) then
  137. create namespace_codes.make (0)
  138. else
  139. namespace_codes := namespace_codes_in_scope
  140. end
  141. apply_namespace_aliases (l_element_uri_code, l_stylesheet)
  142. validate_special_attributes
  143. establish_attribute_names (l_stylesheet)
  144. remove_excluded_namespaces (l_stylesheet)
  145. check attached namespace_codes as l_namespace_codes then
  146. l_namespace_codes.delete (-1)
  147. end
  148. end
  149. validated := True
  150. end
  151. validate_children
  152. -- Validate the children of this node, recursively.
  153. do
  154. if not is_top_level then
  155. Precursor
  156. end
  157. end
  158. compile (a_executable: XM_XSLT_EXECUTABLE)
  159. -- Compile `Current' to an excutable instruction.
  160. local
  161. l_fixed_element: XM_XSLT_FIXED_ELEMENT
  162. l_stylesheet: XM_XSLT_STYLESHEET
  163. l_cursor: DS_ARRAYED_LIST_CURSOR [INTEGER]
  164. l_fixed_attribute: XM_XSLT_FIXED_ATTRIBUTE
  165. l_content: detachable XM_XPATH_EXPRESSION
  166. l_attributes_usage: XM_XSLT_ATTRIBUTE_USAGE
  167. do
  168. last_generated_expression := Void
  169. if not is_top_level then
  170. compile_sequence_constructor (a_executable, new_axis_iterator (Child_axis), True)
  171. l_content := last_generated_expression
  172. check attached attribute_name_codes as l_attribute_name_codes then
  173. if l_attribute_name_codes.count > 0 then
  174. -- Since we cannot output an attribute once we have seen child content,
  175. -- we must place the attributes in the content block prior to any existing
  176. -- content. So we process the attributes back-to-front so they come out
  177. -- in FIFO order.
  178. check attached principal_stylesheet as l_principal_stylesheet then
  179. l_stylesheet := l_principal_stylesheet
  180. end
  181. from
  182. l_cursor := l_attribute_name_codes.new_cursor
  183. l_cursor.finish
  184. until
  185. l_cursor.before
  186. loop
  187. create l_fixed_attribute.make (a_executable, l_cursor.item, Validation_strip, Void, -1)
  188. check attached attribute_values as l_attribute_values then
  189. l_fixed_attribute.set_select_expression (l_attribute_values.item (l_cursor.index))
  190. end
  191. check
  192. module_registered: l_stylesheet.is_module_registered (system_id)
  193. end
  194. l_fixed_attribute.set_source_location (l_stylesheet.module_number (system_id), line_number)
  195. check attached attribute_clean_flags as l_attribute_clean_flags then
  196. if l_attribute_clean_flags.item (l_cursor.index) then
  197. l_fixed_attribute.set_no_special_characters
  198. end
  199. end
  200. if l_content = Void then
  201. l_content := l_fixed_attribute
  202. else
  203. check attached principal_stylesheet as l_principal_stylesheet then
  204. create {XM_XSLT_BLOCK} l_content.make (a_executable, l_fixed_attribute, l_content, l_principal_stylesheet.module_number (system_id), line_number)
  205. end
  206. end
  207. l_cursor.back
  208. variant
  209. l_cursor.index
  210. end
  211. end
  212. end
  213. check attached used_attribute_sets as l_used_attribute_sets then
  214. if not l_used_attribute_sets.is_empty then
  215. create l_attributes_usage.make (a_executable, l_used_attribute_sets)
  216. if l_content = Void then
  217. l_content := l_attributes_usage
  218. else
  219. check attached principal_stylesheet as l_principal_stylesheet then
  220. create {XM_XSLT_BLOCK} l_content.make (a_executable, l_attributes_usage, l_content, l_principal_stylesheet.module_number (system_id), line_number)
  221. end
  222. end
  223. end
  224. end
  225. if l_content = Void then
  226. create {XM_XPATH_EMPTY_SEQUENCE} l_content.make
  227. end
  228. check attached namespace_codes as l_namespace_codes then
  229. create l_fixed_element.make (a_executable, result_name_code, l_namespace_codes, Void, Void, validation, is_inherit_namespaces, l_content)
  230. end
  231. l_fixed_element.set_base_uri (base_uri)
  232. last_generated_expression := l_fixed_element
  233. end
  234. end
  235. constructed_stylesheet (a_compiler: XM_XSLT_STYLESHEET_COMPILER): detachable XM_XPATH_TREE_DOCUMENT
  236. -- Simlified stylesheet constructed around `Current'
  237. require
  238. stylesheet_compiler_not_void: a_compiler /= Void
  239. local
  240. an_xslt_prefix, a_version: detachable STRING
  241. do
  242. an_xslt_prefix := prefix_for_uri (Xslt_uri)
  243. if an_xslt_prefix = Void then
  244. if STRING_.same_string (local_part, "transform")
  245. or else STRING_.same_string (local_part, "stylesheet") then
  246. a_compiler.report_fatal_error ("Namespace for stylesheet element should be " + Xslt_uri, "XTSE0165")
  247. else
  248. a_compiler.report_fatal_error ("The document does not appear to be a stylesheet", "XTSE0165")
  249. end
  250. else
  251. -- Find mandatory xsl:version attribute, and copy it to the new xsl:transform element
  252. a_version := attribute_value (Xslt_version_type_code)
  253. if a_version = Void then
  254. a_compiler.report_fatal_error ("Simplified stylesheet: xsl:version attribute is missing", "XTSE0150")
  255. else
  256. Result := grafted_stylesheet (a_compiler, a_version)
  257. end
  258. end
  259. ensure
  260. error_or_result_not_void: not a_compiler.load_stylesheet_module_failed implies Result /= Void
  261. end
  262. feature {NONE} -- Implementation
  263. -- The next three lists constitute a triple:
  264. attribute_name_codes: detachable DS_ARRAYED_LIST [INTEGER]
  265. -- Name codes for non-XSLT attributes
  266. attribute_values: detachable DS_ARRAYED_LIST [XM_XPATH_EXPRESSION]
  267. -- Values for non-XSLT attributes
  268. attribute_clean_flags: detachable DS_ARRAYED_LIST [BOOLEAN]
  269. -- Flags for non-XSLT attributes indicating whether they are clean for XML output
  270. result_name_code: INTEGER
  271. -- Name code for the resulting output (after namespace-aliasing is taken into account)
  272. namespace_codes: detachable DS_ARRAYED_LIST [INTEGER]
  273. validation: INTEGER
  274. -- Validation level
  275. grafted_stylesheet (a_compiler: XM_XSLT_STYLESHEET_COMPILER; a_version: STRING): detachable XM_XPATH_TREE_DOCUMENT
  276. -- Simlified stylesheet constructed around `Current'
  277. require
  278. stylesheet_compiler_not_void: a_compiler /= Void
  279. version_not_void: a_version /= Void
  280. local
  281. l_builder: detachable XM_XPATH_TREE_BUILDER
  282. l_uri: UT_URI
  283. do
  284. create l_uri.make (system_id)
  285. create l_builder.make (a_compiler.node_factory, system_id, l_uri)
  286. l_builder.open
  287. l_builder.start_document
  288. l_builder.start_element (Xslt_transform_type_code, Untyped_type_code, 0)
  289. l_builder.notify_namespace (Xslt_uri_code, 0)
  290. if not shared_name_pool.is_name_code_allocated (Null_uri, Null_uri, Version_attribute) then
  291. shared_name_pool.allocate_name (Null_uri, Null_uri, Version_attribute)
  292. end
  293. l_builder.notify_attribute (shared_name_pool.name_code (Null_uri, Null_uri, Version_attribute), Untyped_atomic_type_code, a_version, 0)
  294. l_builder.start_content
  295. l_builder.start_element (Xslt_template_type_code, Untyped_type_code, 0)
  296. if not shared_name_pool.is_name_code_allocated (Null_uri, Null_uri, Match_attribute) then
  297. shared_name_pool.allocate_name (Null_uri, Null_uri, Match_attribute)
  298. end
  299. l_builder.notify_attribute (shared_name_pool.name_code (Null_uri, Null_uri, Match_attribute), Untyped_atomic_type_code, "/", 0)
  300. l_builder.start_content
  301. l_builder.graft_element (Current)
  302. l_builder.end_element
  303. l_builder.end_element
  304. l_builder.end_document
  305. l_builder.close
  306. if attached l_builder.last_error as l_last_error then
  307. check has_error: l_builder.has_error end
  308. a_compiler.report_error (l_last_error)
  309. else
  310. Result := l_builder.tree_document
  311. end
  312. ensure
  313. error_or_result_not_void: not a_compiler.load_stylesheet_module_failed implies Result /= Void
  314. rescue
  315. if l_builder /= Void and then attached l_builder.last_error as l_last_error then
  316. check has_error: l_builder.has_error end
  317. a_compiler.report_error (l_last_error)
  318. end
  319. end
  320. is_attribute_checked_clean (an_expression: XM_XPATH_EXPRESSION): BOOLEAN
  321. -- Is `an_expression' guarenteed free of special characters?
  322. require
  323. expression_not_void: an_expression /= Void
  324. local
  325. a_string: STRING
  326. an_index, a_character_code: INTEGER
  327. do
  328. -- If we can be sure the attribute value contains no special XML/HTML characters,
  329. -- we can save the trouble of checking it each time it is output.
  330. -- Note that the check includes characters that need to be escaped in a URL if the
  331. -- output method turns out to be HTML (we don't know the method at compile time).
  332. check attached last_generated_expression as l_last_generated_expression then
  333. if l_last_generated_expression.is_string_value then
  334. a_string := l_last_generated_expression.as_string_value.string_value
  335. Result := True
  336. from
  337. an_index := 1
  338. until
  339. Result = False or else an_index > a_string.count
  340. loop
  341. a_character_code := a_string.item_code (an_index)
  342. if a_character_code < 33 or else a_character_code > 126
  343. or else a_character_code = ('>').code
  344. or else a_character_code = ('<').code
  345. or else a_character_code = ('&').code
  346. or else a_character_code = ('%"').code then
  347. Result := False
  348. end
  349. an_index := an_index + 1
  350. variant
  351. a_string.count + 1 - an_index
  352. end
  353. end
  354. end
  355. end
  356. validate_top_level_element (an_element_uri_code: INTEGER)
  357. -- Validate a top-level LRE.
  358. require
  359. top_level_element: is_top_level
  360. local
  361. an_error: XM_XPATH_ERROR_VALUE
  362. do
  363. -- A top-level element can never be a "real" literal result element,
  364. -- but this class gets used for unknown elements found at the top level
  365. if an_element_uri_code = 0 then
  366. create an_error.make_from_string ("Top level elements must have a non-null namespace URI", Xpath_errors_uri, "XTSE0130", Static_error)
  367. report_compile_error (an_error)
  368. end
  369. end
  370. should_namespaces_be_omitted (an_element_uri_code: INTEGER): BOOLEAN
  371. -- Should namespaces be omitted on output?
  372. require
  373. not_top_level: not is_top_level
  374. positive_uri_code: an_element_uri_code >= 0
  375. local
  376. a_cursor: DS_ARRAYED_LIST_CURSOR [INTEGER]
  377. do
  378. -- If this LRE has a parent that is also an LRE,
  379. -- and if this LRE has no namespace declarations
  380. -- and if the parent doesn't specify inherit-namespaces="no",
  381. -- and if this element name is in the same namespace as its parent,
  382. -- and if there are no attributes in a non-null namespace,
  383. -- then we don't need to output any namespace declarations to the result.
  384. check attached namespace_code_list as l_namespace_code_list then
  385. if (attached {XM_XSLT_LITERAL_RESULT_ELEMENT} parent as a_literal_result_element and then a_literal_result_element.is_inherit_namespaces) and then
  386. l_namespace_code_list.count = 0 and then
  387. an_element_uri_code = shared_name_pool.uri_code_from_name_code (a_literal_result_element.fingerprint) then
  388. Result := True
  389. end
  390. end
  391. if Result then
  392. check attached attribute_collection as l_attribute_collection then
  393. from
  394. a_cursor := l_attribute_collection.name_code_cursor
  395. a_cursor.start
  396. until
  397. a_cursor.after
  398. loop
  399. check attached shared_name_pool.prefix_from_name_code (a_cursor.item) as l_prefix_from_name_code then
  400. if l_prefix_from_name_code.count > 0 then
  401. Result := False
  402. a_cursor.go_after
  403. else
  404. a_cursor.forth
  405. end
  406. end
  407. variant
  408. l_attribute_collection.number_of_attributes + 1 - a_cursor.index
  409. end
  410. end
  411. end
  412. end
  413. apply_namespace_aliases (an_element_uri_code: INTEGER; a_stylesheet: XM_XSLT_STYLESHEET)
  414. -- Apply any aliases required to create the list of output namespaces.
  415. require
  416. not_top_level: not is_top_level
  417. positive_uri_code: an_element_uri_code >= 0
  418. stylesheet_not_void: a_stylesheet /= Void
  419. local
  420. a_cursor: DS_ARRAYED_LIST_CURSOR [INTEGER]
  421. a_source_uri_code, a_namespace_alias_code: INTEGER
  422. an_xml_prefix: STRING
  423. a_uri_code: INTEGER
  424. do
  425. if a_stylesheet.has_namespace_aliases then
  426. check attached namespace_codes as l_namespace_codes then
  427. from
  428. a_cursor := l_namespace_codes.new_cursor
  429. a_cursor.start
  430. until
  431. a_cursor.after
  432. loop
  433. a_source_uri_code := uri_code_from_namespace_code (a_cursor.item)
  434. a_namespace_alias_code := a_stylesheet.namespace_alias (a_source_uri_code)
  435. if a_namespace_alias_code /= -1 and then uri_code_from_namespace_code (a_namespace_alias_code) /= a_source_uri_code then
  436. a_cursor.replace (a_namespace_alias_code)
  437. end
  438. a_cursor.forth
  439. variant
  440. l_namespace_codes.count + 1 - a_cursor.index
  441. end
  442. end
  443. -- Determine if there is an alias for the namespace of the element name.
  444. a_namespace_alias_code := a_stylesheet.namespace_alias (an_element_uri_code)
  445. if a_namespace_alias_code /= -1 then
  446. a_uri_code := uri_code_from_namespace_code (a_namespace_alias_code)
  447. an_xml_prefix := shared_name_pool.prefix_from_namespace_code (a_namespace_alias_code)
  448. if a_uri_code /= an_element_uri_code then
  449. if shared_name_pool.is_name_code_allocated_using_uri_code (an_xml_prefix, a_uri_code, local_part) then
  450. result_name_code := shared_name_pool.name_code (an_xml_prefix, shared_name_pool.uri_from_uri_code (a_uri_code), local_part)
  451. else
  452. shared_name_pool.allocate_name_using_uri_code (an_xml_prefix, a_uri_code, local_part)
  453. result_name_code := shared_name_pool.last_name_code
  454. end
  455. end
  456. end
  457. end
  458. end
  459. validate_special_attributes
  460. -- Validate special attributes.
  461. local
  462. a_use_attribute_sets_attribute, a_type_attribute, a_validation_attribute: detachable STRING
  463. an_error: XM_XPATH_ERROR_VALUE
  464. do
  465. a_use_attribute_sets_attribute := attribute_value (Xslt_use_attribute_sets_type_code)
  466. if a_use_attribute_sets_attribute /= Void then
  467. accumulate_attribute_sets (a_use_attribute_sets_attribute, Void)
  468. else
  469. create used_attribute_sets.make (0)
  470. end
  471. a_type_attribute := attribute_value (Xslt_type_type_code)
  472. if a_type_attribute /= Void then
  473. create an_error.make_from_string ("The type attribute is available only with a schema-aware XSLT processor", Xpath_errors_uri, "XTSE1660", Static_error)
  474. report_compile_error (an_error)
  475. end
  476. a_validation_attribute := attribute_value (Xslt_validation_type_code)
  477. if a_validation_attribute /= Void then
  478. validation := validation_code (a_validation_attribute)
  479. if validation /= Validation_strip then
  480. create an_error.make_from_string ("To perform validation, a schema-aware XSLT processor is needed", Xpath_errors_uri, "XTSE1660", Static_error)
  481. report_compile_error (an_error)
  482. end
  483. else
  484. check attached containing_stylesheet as l_containing_stylesheet then
  485. validation := l_containing_stylesheet.default_validation
  486. end
  487. end
  488. end
  489. establish_attribute_names (a_stylesheet: XM_XSLT_STYLESHEET)
  490. -- Establish the names to be used for all the output attributes.
  491. -- Also type-check the AVT expressions
  492. require
  493. stylesheet_not_void: a_stylesheet /= Void
  494. local
  495. l_cursor: DS_ARRAYED_LIST_CURSOR [INTEGER]
  496. l_alias, l_uri_code, l_other_uri_code, l_namespace_code: INTEGER
  497. l_xml_prefix, l_local_name: STRING
  498. l_expression: XM_XPATH_EXPRESSION
  499. l_replacement: DS_CELL [detachable XM_XPATH_EXPRESSION]
  500. do
  501. check
  502. attached attribute_name_codes as l_attribute_name_codes
  503. attached attribute_values as l_attribute_values
  504. then
  505. from
  506. l_cursor := l_attribute_name_codes.new_cursor
  507. l_cursor.start
  508. until
  509. l_cursor.after
  510. loop
  511. l_alias := l_cursor.item
  512. l_uri_code := shared_name_pool.uri_code_from_name_code (l_alias)
  513. if l_uri_code /= 0 then -- attribute has a namespace prefix
  514. l_namespace_code := -1
  515. if a_stylesheet.has_namespace_aliases then
  516. l_namespace_code := a_stylesheet.namespace_alias (l_uri_code)
  517. end
  518. l_other_uri_code := uri_code_from_namespace_code (l_namespace_code)
  519. if l_namespace_code /= -1 and then l_other_uri_code /= l_uri_code then
  520. l_uri_code := l_other_uri_code
  521. l_xml_prefix := shared_name_pool.prefix_from_namespace_code (l_namespace_code)
  522. l_local_name := shared_name_pool.local_name_from_name_code (l_cursor.item)
  523. if shared_name_pool.is_name_code_allocated_using_uri_code (l_xml_prefix, l_uri_code, l_local_name) then
  524. l_alias := shared_name_pool.name_code (l_xml_prefix, shared_name_pool.uri_from_uri_code (l_uri_code), l_local_name)
  525. else
  526. shared_name_pool.allocate_name_using_uri_code (l_xml_prefix, l_uri_code, l_local_name)
  527. l_alias := shared_name_pool.last_name_code
  528. end
  529. end
  530. end
  531. l_cursor.replace (l_alias)
  532. l_expression := l_attribute_values.item (l_cursor.index)
  533. create l_replacement.make (Void)
  534. type_check_expression (l_replacement, shared_name_pool.display_name_from_name_code (l_alias), l_expression)
  535. if l_expression /= l_replacement.item then
  536. check attached l_replacement.item as l_replacement_item then
  537. l_attribute_values.replace (l_replacement_item, l_cursor.index)
  538. end
  539. end
  540. l_cursor.forth
  541. variant
  542. l_attribute_name_codes.count + 1 - l_cursor.index
  543. end
  544. end
  545. end
  546. excluded_namespace_count: INTEGER
  547. -- Number of namespaces excluded
  548. remove_excluded_namespaces (a_stylesheet: XM_XSLT_STYLESHEET)
  549. -- Remove any namespace that is on the exclude-result-prefixes list,
  550. -- unless it is the namespace of the element or an attribute.
  551. require
  552. no_namespaces_excluded_yet: excluded_namespace_count = 0
  553. stylesheet_not_void: a_stylesheet /= Void
  554. local
  555. l_cursor: DS_ARRAYED_LIST_CURSOR [INTEGER]
  556. l_uri_code: INTEGER
  557. do
  558. check attached namespace_codes as l_namespace_codes then
  559. from
  560. l_cursor := l_namespace_codes.new_cursor
  561. l_cursor.start
  562. until
  563. l_cursor.after
  564. loop
  565. l_uri_code := uri_code_from_namespace_code (l_cursor.item)
  566. if is_excluded_namespace (l_uri_code) and then
  567. not a_stylesheet.is_alias_result_namespace (l_uri_code) then
  568. -- Exclude it from the output namespace list.
  569. l_namespace_codes.replace (-1, l_cursor.index)
  570. excluded_namespace_count := excluded_namespace_count + 1
  571. end
  572. l_cursor.forth
  573. variant
  574. l_namespace_codes.count + 1 - l_cursor.index
  575. end
  576. end
  577. end
  578. invariant
  579. attribute_lists_not_void: attributes_prepared implies attribute_name_codes /= Void and attribute_values /= Void and attribute_clean_flags /= Void
  580. attribute_lists_consistent_length: attributes_prepared implies (attached attribute_name_codes as l_attribute_name_codes and attached attribute_values as l_attribute_values and attached attribute_clean_flags as l_attribute_clean_flags) and then (l_attribute_name_codes.count = l_attribute_values.count and l_attribute_values.count = l_attribute_clean_flags.count)
  581. positive_excluded_namespace_count: excluded_namespace_count >= 0
  582. end