xml2text.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. xml2text.xsl - transform Bison XML Report into plain text.
  4. Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc.
  5. This file is part of Bison, the GNU Compiler Compiler.
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. Written by Wojciech Polak <[email protected]>.
  17. -->
  18. <xsl:stylesheet version="1.0"
  19. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  20. xmlns:bison="https://www.gnu.org/software/bison/">
  21. <xsl:import href="bison.xsl"/>
  22. <xsl:output method="text" encoding="UTF-8" indent="no"/>
  23. <xsl:template match="/">
  24. <xsl:apply-templates select="bison-xml-report"/>
  25. </xsl:template>
  26. <xsl:template match="bison-xml-report">
  27. <xsl:apply-templates select="grammar" mode="reductions"/>
  28. <xsl:apply-templates select="grammar" mode="useless-in-parser"/>
  29. <xsl:apply-templates select="automaton" mode="conflicts"/>
  30. <xsl:apply-templates select="grammar"/>
  31. <xsl:apply-templates select="automaton"/>
  32. </xsl:template>
  33. <xsl:template match="grammar" mode="reductions">
  34. <xsl:apply-templates select="nonterminals" mode="useless-in-grammar"/>
  35. <xsl:apply-templates select="terminals" mode="unused-in-grammar"/>
  36. <xsl:apply-templates select="rules" mode="useless-in-grammar"/>
  37. </xsl:template>
  38. <xsl:template match="nonterminals" mode="useless-in-grammar">
  39. <xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
  40. <xsl:text>Nonterminals useless in grammar&#10;&#10;</xsl:text>
  41. <xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
  42. <xsl:text> </xsl:text>
  43. <xsl:value-of select="@name"/>
  44. <xsl:text>&#10;</xsl:text>
  45. </xsl:for-each>
  46. <xsl:text>&#10;&#10;</xsl:text>
  47. </xsl:if>
  48. </xsl:template>
  49. <xsl:template match="terminals" mode="unused-in-grammar">
  50. <xsl:if test="terminal[@usefulness='unused-in-grammar']">
  51. <xsl:text>Terminals unused in grammar&#10;&#10;</xsl:text>
  52. <xsl:for-each select="terminal[@usefulness='unused-in-grammar']">
  53. <xsl:sort select="@symbol-number" data-type="number"/>
  54. <xsl:text> </xsl:text>
  55. <xsl:value-of select="@name"/>
  56. <xsl:text>&#10;</xsl:text>
  57. </xsl:for-each>
  58. <xsl:text>&#10;&#10;</xsl:text>
  59. </xsl:if>
  60. </xsl:template>
  61. <xsl:template match="rules" mode="useless-in-grammar">
  62. <xsl:variable name="set" select="rule[@usefulness='useless-in-grammar']"/>
  63. <xsl:if test="$set">
  64. <xsl:text>Rules useless in grammar&#10;</xsl:text>
  65. <xsl:call-template name="style-rule-set">
  66. <xsl:with-param name="rule-set" select="$set"/>
  67. </xsl:call-template>
  68. <xsl:text>&#10;&#10;</xsl:text>
  69. </xsl:if>
  70. </xsl:template>
  71. <xsl:template match="grammar" mode="useless-in-parser">
  72. <xsl:variable
  73. name="set" select="rules/rule[@usefulness='useless-in-parser']"
  74. />
  75. <xsl:if test="$set">
  76. <xsl:text>Rules useless in parser due to conflicts&#10;</xsl:text>
  77. <xsl:call-template name="style-rule-set">
  78. <xsl:with-param name="rule-set" select="$set"/>
  79. </xsl:call-template>
  80. <xsl:text>&#10;&#10;</xsl:text>
  81. </xsl:if>
  82. </xsl:template>
  83. <xsl:template match="grammar">
  84. <xsl:text>Grammar&#10;</xsl:text>
  85. <xsl:call-template name="style-rule-set">
  86. <xsl:with-param
  87. name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
  88. />
  89. </xsl:call-template>
  90. <xsl:text>&#10;&#10;</xsl:text>
  91. <xsl:apply-templates select="terminals"/>
  92. <xsl:apply-templates select="nonterminals"/>
  93. </xsl:template>
  94. <xsl:template name="style-rule-set">
  95. <xsl:param name="rule-set"/>
  96. <xsl:for-each select="$rule-set">
  97. <xsl:apply-templates select=".">
  98. <xsl:with-param name="pad" select="'3'"/>
  99. <xsl:with-param name="prev-lhs">
  100. <xsl:if test="position()>1">
  101. <xsl:variable name="position" select="position()"/>
  102. <xsl:value-of select="$rule-set[$position - 1]/lhs"/>
  103. </xsl:if>
  104. </xsl:with-param>
  105. </xsl:apply-templates>
  106. </xsl:for-each>
  107. </xsl:template>
  108. <xsl:template match="grammar/terminals">
  109. <xsl:text>Terminals, with rules where they appear&#10;&#10;</xsl:text>
  110. <xsl:apply-templates select="terminal"/>
  111. <xsl:text>&#10;&#10;</xsl:text>
  112. </xsl:template>
  113. <xsl:template match="grammar/nonterminals">
  114. <xsl:text>Nonterminals, with rules where they appear&#10;&#10;</xsl:text>
  115. <xsl:apply-templates select="nonterminal[@usefulness!='useless-in-grammar']"/>
  116. </xsl:template>
  117. <xsl:template match="terminal">
  118. <xsl:text> </xsl:text>
  119. <xsl:value-of select="@name"/>
  120. <xsl:call-template name="line-wrap">
  121. <xsl:with-param name="first-line-length">
  122. <xsl:choose>
  123. <xsl:when test="string-length(@name) &gt; 66">0</xsl:when>
  124. <xsl:otherwise>
  125. <xsl:value-of select="66 - string-length(@name)" />
  126. </xsl:otherwise>
  127. </xsl:choose>
  128. </xsl:with-param>
  129. <xsl:with-param name="line-length" select="66" />
  130. <xsl:with-param name="text">
  131. <xsl:if test="string-length(@type) != 0">
  132. <xsl:value-of select="concat(' &lt;', @type, '&gt;')"/>
  133. </xsl:if>
  134. <xsl:value-of select="concat(' (', @token-number, ')')"/>
  135. <xsl:for-each select="key('bison:ruleByRhs', @name)">
  136. <xsl:value-of select="concat(' ', @number)"/>
  137. </xsl:for-each>
  138. </xsl:with-param>
  139. </xsl:call-template>
  140. </xsl:template>
  141. <xsl:template match="nonterminal">
  142. <xsl:text> </xsl:text>
  143. <xsl:value-of select="@name"/>
  144. <xsl:if test="string-length(@type) != 0">
  145. <xsl:value-of select="concat(' &lt;', @type, '&gt;')"/>
  146. </xsl:if>
  147. <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
  148. <xsl:text>&#10;</xsl:text>
  149. <xsl:variable name="output">
  150. <xsl:call-template name="line-wrap">
  151. <xsl:with-param name="line-length" select="66" />
  152. <xsl:with-param name="text">
  153. <xsl:text> </xsl:text>
  154. <xsl:if test="key('bison:ruleByLhs', @name)">
  155. <xsl:text>on@left:</xsl:text>
  156. <xsl:for-each select="key('bison:ruleByLhs', @name)">
  157. <xsl:value-of select="concat(' ', @number)"/>
  158. </xsl:for-each>
  159. </xsl:if>
  160. <xsl:if test="key('bison:ruleByRhs', @name)">
  161. <xsl:if test="key('bison:ruleByLhs', @name)">
  162. <xsl:text>&#10; </xsl:text>
  163. </xsl:if>
  164. <xsl:text>on@right:</xsl:text>
  165. <xsl:for-each select="key('bison:ruleByRhs', @name)">
  166. <xsl:value-of select="concat(' ', @number)"/>
  167. </xsl:for-each>
  168. </xsl:if>
  169. </xsl:with-param>
  170. </xsl:call-template>
  171. </xsl:variable>
  172. <xsl:value-of select="translate($output, '@', ' ')" />
  173. </xsl:template>
  174. <xsl:template match="automaton" mode="conflicts">
  175. <xsl:variable name="conflict-report">
  176. <xsl:apply-templates select="state" mode="conflicts"/>
  177. </xsl:variable>
  178. <xsl:if test="string-length($conflict-report) != 0">
  179. <xsl:value-of select="$conflict-report"/>
  180. <xsl:text>&#10;&#10;</xsl:text>
  181. </xsl:if>
  182. </xsl:template>
  183. <xsl:template match="state" mode="conflicts">
  184. <xsl:variable name="conflict-counts">
  185. <xsl:apply-templates select="." mode="bison:count-conflicts" />
  186. </xsl:variable>
  187. <xsl:variable
  188. name="sr-count" select="substring-before($conflict-counts, ',')"
  189. />
  190. <xsl:variable
  191. name="rr-count" select="substring-after($conflict-counts, ',')"
  192. />
  193. <xsl:if test="$sr-count > 0 or $rr-count > 0">
  194. <xsl:value-of select="concat('State ', @number, ' conflicts:')"/>
  195. <xsl:if test="$sr-count > 0">
  196. <xsl:value-of select="concat(' ', $sr-count, ' shift/reduce')"/>
  197. <xsl:if test="$rr-count > 0">
  198. <xsl:value-of select="(',')"/>
  199. </xsl:if>
  200. </xsl:if>
  201. <xsl:if test="$rr-count > 0">
  202. <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
  203. </xsl:if>
  204. <xsl:value-of select="'&#10;'"/>
  205. </xsl:if>
  206. </xsl:template>
  207. <xsl:template match="automaton">
  208. <xsl:apply-templates select="state">
  209. <xsl:with-param name="pad" select="'3'"/>
  210. </xsl:apply-templates>
  211. </xsl:template>
  212. <xsl:template match="automaton/state">
  213. <xsl:param name="pad"/>
  214. <xsl:text>&#10;&#10;</xsl:text>
  215. <xsl:text>State </xsl:text>
  216. <xsl:value-of select="@number"/>
  217. <xsl:text>&#10;&#10;</xsl:text>
  218. <xsl:apply-templates select="itemset/item">
  219. <xsl:with-param name="pad" select="$pad"/>
  220. </xsl:apply-templates>
  221. <xsl:apply-templates select="actions/transitions">
  222. <xsl:with-param name="type" select="'shift'"/>
  223. </xsl:apply-templates>
  224. <xsl:apply-templates select="actions/errors"/>
  225. <xsl:apply-templates select="actions/reductions"/>
  226. <xsl:apply-templates select="actions/transitions">
  227. <xsl:with-param name="type" select="'goto'"/>
  228. </xsl:apply-templates>
  229. <xsl:apply-templates select="solved-conflicts"/>
  230. </xsl:template>
  231. <xsl:template match="actions/transitions">
  232. <xsl:param name="type"/>
  233. <xsl:if test="transition[@type = $type]">
  234. <xsl:text>&#10;</xsl:text>
  235. <xsl:apply-templates select="transition[@type = $type]">
  236. <xsl:with-param name="pad">
  237. <xsl:call-template name="max-width-symbol">
  238. <xsl:with-param name="node" select="transition[@type = $type]"/>
  239. </xsl:call-template>
  240. </xsl:with-param>
  241. </xsl:apply-templates>
  242. </xsl:if>
  243. </xsl:template>
  244. <xsl:template match="actions/errors">
  245. <xsl:if test="error">
  246. <xsl:text>&#10;</xsl:text>
  247. <xsl:apply-templates select="error">
  248. <xsl:with-param name="pad">
  249. <xsl:call-template name="max-width-symbol">
  250. <xsl:with-param name="node" select="error"/>
  251. </xsl:call-template>
  252. </xsl:with-param>
  253. </xsl:apply-templates>
  254. </xsl:if>
  255. </xsl:template>
  256. <xsl:template match="actions/reductions">
  257. <xsl:if test="reduction">
  258. <xsl:text>&#10;</xsl:text>
  259. <xsl:apply-templates select="reduction">
  260. <xsl:with-param name="pad">
  261. <xsl:call-template name="max-width-symbol">
  262. <xsl:with-param name="node" select="reduction"/>
  263. </xsl:call-template>
  264. </xsl:with-param>
  265. </xsl:apply-templates>
  266. </xsl:if>
  267. </xsl:template>
  268. <xsl:template match="item">
  269. <xsl:param name="pad"/>
  270. <xsl:param name="prev-rule-number"
  271. select="preceding-sibling::item[1]/@rule-number"/>
  272. <xsl:apply-templates
  273. select="key('bison:ruleByNumber', current()/@rule-number)"
  274. >
  275. <xsl:with-param name="itemset" select="'true'"/>
  276. <xsl:with-param name="pad" select="$pad"/>
  277. <xsl:with-param
  278. name="prev-lhs"
  279. select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
  280. />
  281. <xsl:with-param name="dot" select="@dot"/>
  282. <xsl:with-param name="lookaheads">
  283. <xsl:apply-templates select="lookaheads"/>
  284. </xsl:with-param>
  285. </xsl:apply-templates>
  286. </xsl:template>
  287. <xsl:template match="rule">
  288. <xsl:param name="itemset"/>
  289. <xsl:param name="pad"/>
  290. <xsl:param name="prev-lhs"/>
  291. <xsl:param name="dot"/>
  292. <xsl:param name="lookaheads"/>
  293. <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
  294. <xsl:text>&#10;</xsl:text>
  295. </xsl:if>
  296. <xsl:text> </xsl:text>
  297. <xsl:call-template name="lpad">
  298. <xsl:with-param name="str" select="string(@number)"/>
  299. <xsl:with-param name="pad" select="number($pad)"/>
  300. </xsl:call-template>
  301. <xsl:text> </xsl:text>
  302. <!-- LHS -->
  303. <xsl:choose>
  304. <xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]">
  305. <xsl:call-template name="lpad">
  306. <xsl:with-param name="str" select="'|'"/>
  307. <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
  308. </xsl:call-template>
  309. </xsl:when>
  310. <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
  311. <xsl:call-template name="lpad">
  312. <xsl:with-param name="str" select="'|'"/>
  313. <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
  314. </xsl:call-template>
  315. </xsl:when>
  316. <xsl:otherwise>
  317. <xsl:value-of select="lhs"/>
  318. <xsl:text>:</xsl:text>
  319. </xsl:otherwise>
  320. </xsl:choose>
  321. <!-- RHS -->
  322. <xsl:for-each select="rhs/*">
  323. <xsl:if test="position() = $dot + 1">
  324. <xsl:text> •</xsl:text>
  325. </xsl:if>
  326. <xsl:apply-templates select="."/>
  327. <xsl:if test="position() = last() and position() = $dot">
  328. <xsl:text> •</xsl:text>
  329. </xsl:if>
  330. </xsl:for-each>
  331. <xsl:if test="$lookaheads">
  332. <xsl:value-of select="$lookaheads"/>
  333. </xsl:if>
  334. <xsl:text>&#10;</xsl:text>
  335. </xsl:template>
  336. <xsl:template match="symbol">
  337. <xsl:text> </xsl:text>
  338. <xsl:value-of select="."/>
  339. </xsl:template>
  340. <xsl:template match="empty">
  341. <xsl:text> %empty</xsl:text>
  342. </xsl:template>
  343. <xsl:template match="lookaheads">
  344. <xsl:text> [</xsl:text>
  345. <xsl:apply-templates select="symbol"/>
  346. <xsl:text>]</xsl:text>
  347. </xsl:template>
  348. <xsl:template match="lookaheads/symbol">
  349. <xsl:value-of select="."/>
  350. <xsl:if test="position() != last()">
  351. <xsl:text>, </xsl:text>
  352. </xsl:if>
  353. </xsl:template>
  354. <xsl:template match="transition">
  355. <xsl:param name="pad"/>
  356. <xsl:text> </xsl:text>
  357. <xsl:call-template name="rpad">
  358. <xsl:with-param name="str" select="string(@symbol)"/>
  359. <xsl:with-param name="pad" select="number($pad) + 2"/>
  360. </xsl:call-template>
  361. <xsl:choose>
  362. <xsl:when test="@type = 'shift'">
  363. <xsl:text>shift, and go to state </xsl:text>
  364. <xsl:value-of select="@state"/>
  365. </xsl:when>
  366. <xsl:when test="@type = 'goto'">
  367. <xsl:text>go to state </xsl:text>
  368. <xsl:value-of select="@state"/>
  369. </xsl:when>
  370. </xsl:choose>
  371. <xsl:text>&#10;</xsl:text>
  372. </xsl:template>
  373. <xsl:template match="error">
  374. <xsl:param name="pad"/>
  375. <xsl:text> </xsl:text>
  376. <xsl:call-template name="rpad">
  377. <xsl:with-param name="str" select="string(@symbol)"/>
  378. <xsl:with-param name="pad" select="number($pad) + 2"/>
  379. </xsl:call-template>
  380. <xsl:text>error</xsl:text>
  381. <xsl:text> (</xsl:text>
  382. <xsl:value-of select="text()"/>
  383. <xsl:text>)</xsl:text>
  384. <xsl:text>&#10;</xsl:text>
  385. </xsl:template>
  386. <xsl:template match="reduction">
  387. <xsl:param name="pad"/>
  388. <xsl:text> </xsl:text>
  389. <xsl:call-template name="rpad">
  390. <xsl:with-param name="str" select="string(@symbol)"/>
  391. <xsl:with-param name="pad" select="number($pad) + 2"/>
  392. </xsl:call-template>
  393. <xsl:if test="@enabled = 'false'">
  394. <xsl:text>[</xsl:text>
  395. </xsl:if>
  396. <xsl:choose>
  397. <xsl:when test="@rule = 'accept'">
  398. <xsl:text>accept</xsl:text>
  399. </xsl:when>
  400. <xsl:otherwise>
  401. <xsl:text>reduce using rule </xsl:text>
  402. <xsl:value-of select="@rule"/>
  403. <xsl:text> (</xsl:text>
  404. <xsl:value-of
  405. select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/>
  406. <xsl:text>)</xsl:text>
  407. </xsl:otherwise>
  408. </xsl:choose>
  409. <xsl:if test="@enabled = 'false'">
  410. <xsl:text>]</xsl:text>
  411. </xsl:if>
  412. <xsl:text>&#10;</xsl:text>
  413. </xsl:template>
  414. <xsl:template match="solved-conflicts">
  415. <xsl:if test="resolution">
  416. <xsl:text>&#10;</xsl:text>
  417. <xsl:apply-templates select="resolution"/>
  418. </xsl:if>
  419. </xsl:template>
  420. <xsl:template match="resolution">
  421. <xsl:text> Conflict between rule </xsl:text>
  422. <xsl:value-of select="@rule"/>
  423. <xsl:text> and token </xsl:text>
  424. <xsl:value-of select="@symbol"/>
  425. <xsl:text> resolved as </xsl:text>
  426. <xsl:if test="@type = 'error'">
  427. <xsl:text>an </xsl:text>
  428. </xsl:if>
  429. <xsl:value-of select="@type"/>
  430. <xsl:text> (</xsl:text>
  431. <xsl:value-of select="."/>
  432. <xsl:text>).&#10;</xsl:text>
  433. </xsl:template>
  434. <xsl:template name="max-width-symbol">
  435. <xsl:param name="node"/>
  436. <xsl:variable name="longest">
  437. <xsl:for-each select="$node">
  438. <xsl:sort data-type="number" select="string-length(@symbol)"
  439. order="descending"/>
  440. <xsl:if test="position() = 1">
  441. <xsl:value-of select="string-length(@symbol)"/>
  442. </xsl:if>
  443. </xsl:for-each>
  444. </xsl:variable>
  445. <xsl:value-of select="$longest"/>
  446. </xsl:template>
  447. <xsl:template name="lpad">
  448. <xsl:param name="str" select="''"/>
  449. <xsl:param name="pad" select="0"/>
  450. <xsl:variable name="diff" select="$pad - string-length($str)" />
  451. <xsl:choose>
  452. <xsl:when test="$diff &lt; 0">
  453. <xsl:value-of select="$str"/>
  454. </xsl:when>
  455. <xsl:otherwise>
  456. <xsl:call-template name="space">
  457. <xsl:with-param name="repeat" select="$diff"/>
  458. </xsl:call-template>
  459. <xsl:value-of select="$str"/>
  460. </xsl:otherwise>
  461. </xsl:choose>
  462. </xsl:template>
  463. <xsl:template name="rpad">
  464. <xsl:param name="str" select="''"/>
  465. <xsl:param name="pad" select="0"/>
  466. <xsl:variable name="diff" select="$pad - string-length($str)"/>
  467. <xsl:choose>
  468. <xsl:when test="$diff &lt; 0">
  469. <xsl:value-of select="$str"/>
  470. </xsl:when>
  471. <xsl:otherwise>
  472. <xsl:value-of select="$str"/>
  473. <xsl:call-template name="space">
  474. <xsl:with-param name="repeat" select="$diff"/>
  475. </xsl:call-template>
  476. </xsl:otherwise>
  477. </xsl:choose>
  478. </xsl:template>
  479. <xsl:template name="line-wrap">
  480. <xsl:param name="line-length"/> <!-- required -->
  481. <xsl:param name="first-line-length" select="$line-length"/>
  482. <xsl:param name="text"/> <!-- required -->
  483. <xsl:choose>
  484. <xsl:when test="normalize-space($text) = ''" />
  485. <xsl:when test="string-length($text) &lt;= $first-line-length">
  486. <xsl:value-of select="concat($text, '&#10;')" />
  487. </xsl:when>
  488. <xsl:otherwise>
  489. <xsl:variable name="break-pos">
  490. <xsl:call-template name="ws-search">
  491. <xsl:with-param name="text" select="$text" />
  492. <xsl:with-param name="start" select="$first-line-length+1" />
  493. </xsl:call-template>
  494. </xsl:variable>
  495. <xsl:value-of select="substring($text, 1, $break-pos - 1)" />
  496. <xsl:text>&#10;</xsl:text>
  497. <xsl:call-template name="line-wrap">
  498. <xsl:with-param name="line-length" select="$line-length" />
  499. <xsl:with-param
  500. name="text" select="concat(' ', substring($text, $break-pos+1))"
  501. />
  502. </xsl:call-template>
  503. </xsl:otherwise>
  504. </xsl:choose>
  505. </xsl:template>
  506. <xsl:template name="ws-search">
  507. <xsl:param name="text"/> <!-- required -->
  508. <xsl:param name="start"/> <!-- required -->
  509. <xsl:variable name="search-text" select="substring($text, $start)" />
  510. <xsl:choose>
  511. <xsl:when test="not(contains($search-text, ' '))">
  512. <xsl:value-of select="string-length($text)+1" />
  513. </xsl:when>
  514. <xsl:otherwise>
  515. <xsl:value-of
  516. select="$start + string-length(substring-before($search-text, ' '))"
  517. />
  518. </xsl:otherwise>
  519. </xsl:choose>
  520. </xsl:template>
  521. </xsl:stylesheet>