Posted to tcl by oldlaptop at Fri May 23 23:40:26 GMT 2025view raw

  1. I don't really have much of a clue what I'm doing with TMML as yet. I also question whether this might be a bit too exhaustively detailed (especially LIMITS - those won't change automatically when the corresponding #defines/magic numbers change, even supposing I have them right. :)).
  2.  
  3. Index: doc/domNode.xml
  4. ==================================================================
  5. --- doc/domNode.xml
  6. +++ doc/domNode.xml
  7. @@ -701,10 +701,11 @@
  8. <ref>domDoc</ref>
  9. </seealso>
  10.  
  11. <keywords>
  12. <keyword>XML</keyword>
  13. + <keyword>XPath</keyword>
  14. <keyword>DOM</keyword>
  15. <keyword>document</keyword>
  16. <keyword>node</keyword>
  17. <keyword>parsing</keyword>
  18. </keywords>
  19.  
  20. Index: doc/tDOM.xml
  21. ==================================================================
  22. --- doc/tDOM.xml
  23. +++ doc/tDOM.xml
  24. @@ -1,9 +1,10 @@
  25. <!DOCTYPE manual PUBLIC "-//jenglish//DTD TMML 0.5//EN" "tmml.dtd" [
  26. <!ENTITY dom SYSTEM "dom.xml">
  27. <!ENTITY domDoc SYSTEM "domDoc.xml">
  28. <!ENTITY domNode SYSTEM "domNode.xml">
  29. +<!ENTITY xpathFunc SYSTEM "xpathFunc.xml">
  30. <!ENTITY expat SYSTEM "expat.xml">
  31. <!ENTITY expatapi SYSTEM "expatapi.xml">
  32. <!ENTITY pullparser SYSTEM "pullparser.xml">
  33. <!ENTITY schema SYSTEM "schema.xml">
  34. <!ENTITY tdomcmd SYSTEM "tdomcmd.xml">
  35. @@ -15,10 +16,12 @@
  36. &dom;
  37.  
  38. &domDoc;
  39.  
  40. &domNode;
  41. +
  42. +&xpathFunc;
  43.  
  44. &expat;
  45.  
  46. &expatapi;
  47.  
  48.  
  49. ADDED doc/xpathFunc.xml
  50. Index: doc/xpathFunc.xml
  51. ==================================================================
  52. --- /dev/null
  53. +++ doc/xpathFunc.xml
  54. @@ -0,0 +1,150 @@
  55. +<manpage id="xpathFunc" title="xpathFunc" cat="misc">
  56. + <namesection>
  57. + <name>::dom::xpathFunc</name>
  58. + <desc>Scripted XPath functions</desc>
  59. + </namesection>
  60. +
  61. + <synopsis>
  62. + <syntax>::dom::xpathFunc::<m>funcName</m> <m>ctxNode</m> <m>pos</m> <m>nodeListType</m> <m>nodeList</m> ?<m>type arg type arg...</m>?
  63. +::dom::xpathFunc::<m>namespaceURL</m>::<m>funcName</m> <m>ctxNode</m> <m>pos</m> <m>nodeListType</m> <m>nodeList</m> ?<m>type arg type arg...</m>?</syntax>
  64. + </synopsis>
  65. +
  66. + <section>
  67. + <title>DESCRIPTION</title>
  68. + <p>
  69. + tDOM's XPath engine supports custom XPath functions implemented by Tcl
  70. + commands. When it encounters a function call to an unknown function name
  71. + without a namespace qualifier, the XPath engine looks for a Tcl command of
  72. + the same name in the <l>::dom::xpathFunc</l> namespace. If it encounters
  73. + an unknown namespace-qualified function call, it looks for a Tcl namespace
  74. + with a name equal to the function's full namespace URI inside
  75. + <l>::dom::xpathFunc</l>, and a Tcl command named for the local part of the
  76. + function's name inside that namespace. If it finds such a Tcl command, it
  77. + is executed with at least the following arguments, to describe the current
  78. + XPath context:
  79. + </p>
  80. +
  81. + <dl>
  82. + <dle>
  83. + <dt>ctxNode</dt>
  84. + <dd>The <l>domNode</l> object command of the XPath context node.</dd>
  85. + </dle>
  86. + <dle>
  87. + <dt>pos</dt>
  88. + <dd>
  89. + The XPath context position, in zero-based form - that is, the return
  90. + value of the standard XPath <l>position()</l> function in the context
  91. + would be <l>$pos - 1</l>.
  92. + </dd>
  93. + </dle>
  94. + <dle>
  95. + <dt>nodeListType</dt>
  96. + <dd>
  97. + The type name for <m>nodeList</m>, as for the
  98. + <method>selectNodes</method> method's <m>typeVar</m>.
  99. + </dd>
  100. + </dle>
  101. + <dle>
  102. + <dt>nodeList</dt>
  103. + <dd>
  104. + A list of the <l>domNode</l> object commands of the context node and
  105. + all of its siblings, in document order. <m>ctxNode</m> will be equal
  106. + to <l>[lindex $nodeList $pos]</l>.
  107. + </dd>
  108. + </dle>
  109. + </dl>
  110. +
  111. + <p>
  112. + If the function call includes any arguments, two arguments will be
  113. + appended to the command's argument list for each one:
  114. + </p>
  115. + <dl>
  116. + <dle>
  117. + <dt>type</dt>
  118. + <dd>
  119. + The argument's type name, as for <method>selectNodes</method>'s
  120. + <m>typeVar</m>.
  121. + </dd>
  122. + </dle>
  123. + <dle>
  124. + <dt>val</dt>
  125. + <dd>
  126. + The argument's value, as <method>selectNodes</method> would return
  127. + it in an XPath expression's result set.
  128. + </dd>
  129. + </dle>
  130. + </dl>
  131. +
  132. + <p>
  133. + The command is required to return a 1- or 2-element Tcl list to provide
  134. + the result of the XPath function call. If the result list has two
  135. + elements, the first is the result's XPath type name, and the second is an
  136. + appropriately encoded value (note that the <m>attrnodes</m> type name is
  137. + not supported):
  138. + </p>
  139. + <dl>
  140. + <dle>
  141. + <dt>bool</dt>
  142. + <dd>Tcl boolean value acceptable to <fun>Tcl_GetBooleanFromObj</fun>.</dd>
  143. + </dle>
  144. + <dle>
  145. + <dt>number</dt>
  146. + <dd>
  147. + Tcl numeric value acceptable to <fun>Tcl_GetSizeIntFromObj</fun> or
  148. + <fun>Tcl_GetDoubleFromObj</fun>.
  149. + </dd>
  150. + </dle>
  151. + <dle>
  152. + <dt>string</dt><dd>Simple string.</dd>
  153. + </dle>
  154. + <dle>
  155. + <dt>nodes</dt><dd>Tcl list of <l>domNode</l> object commands.</dd>
  156. + </dle>
  157. + <dle>
  158. + <dt>attrvalues</dt><dd>Alias for <m>string</m>.</dd>
  159. + </dle>
  160. + </dl>
  161. + <p>
  162. + If the result list has only one element, it is treated as a simple string.
  163. + It is an error for the result to have zero elements, more than two
  164. + elements, or to be invalid as a Tcl list, and it is an error if the
  165. + <m>val</m> of a two-part result does not match the requirements described
  166. + above for its <m>type</m>.
  167. + </p>
  168. + </section>
  169. +
  170. + <section>
  171. + <title>EXAMPLES</title>
  172. + <p>
  173. + A simple workalike for the XPath 2/3 <l>fn:matches()</l> function, not
  174. + otherwise available in an XPath 1.0 engine such as tDOM's:
  175. + </p>
  176. + <example>proc ::dom::xpathFunc::regmatch {
  177. + ctxNode pos nodeListType nodeList
  178. + inputType inputVal patternType patternVal
  179. +} {
  180. + set input [::dom::xpathFuncHelper::coerce2string $inputType $inputVal]
  181. + set pattern [::dom::xpathFuncHelper::coerce2string $patternType $patternVal]
  182. + return [list bool [regexp $pattern $input]]
  183. +}</example>
  184. + </section>
  185. +
  186. + <section>
  187. + <title>LIMITS</title>
  188. + <p>
  189. + Function names are limited to 200 characters, including any namespace URI
  190. + and the <l>::</l> Tcl namespace separator between it and the local part.
  191. + Function calls may have a maximum of 20 arguments. Tcl commands created
  192. + with the deprecated <fun>Tcl_CreateCommand</fun> interface cannot be used
  193. + as scripted XPath functions.
  194. + </p>
  195. + </section>
  196. +
  197. + <seealso>
  198. + <ref>domNode</ref>
  199. + </seealso>
  200. +
  201. + <keywords>
  202. + <keyword>XPath</keyword>
  203. + </keywords>
  204. +</manpage>
  205.  
  206.  

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week