tabularForm.xslt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. ##############################################################################
  4. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ##############################################################################
  18. -->
  19. <!DOCTYPE xsl:stylesheet [
  20. <!ENTITY endl "&#xd;&#xa;">
  21. <!ENTITY nbsp "&#160;"><!--define the HTML non-breaking space:-->
  22. ]>
  23. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  24. xmlns:external="http://www.seisint.com" exclude-result-prefixes="external">
  25. <xsl:param name="Component" select="'ws_roxieconfig'"/>
  26. <xsl:param name="Command" select="'DeployECLAttributes'"/>
  27. <xsl:param name="ArgsNodeName" select="'Arguments'"/>
  28. <xsl:output method="html" indent="yes" encoding="utf-8"/>
  29. <xsl:template match="/">
  30. <html>
  31. <head>
  32. <title>
  33. <xsl:value-of select="$Command"/>
  34. </title>
  35. <link type="text/css" rel="StyleSheet" href="/esp/files_/css/sortabletable.css"/>
  36. <style type="text/css">
  37. .sort-table td {
  38. text-align:center;
  39. }
  40. </style>
  41. <script type="text/javascript" src="/esp/files_/scripts/tabularForm.js">
  42. </script>
  43. </head>
  44. <body onload="onLoad()">
  45. <xml id="xmlPrevArgsDoc">
  46. <xsl:copy-of select="."/>
  47. </xml>
  48. <form method="post" action="/{$Component}/{$Command}" onsubmit="return onSubmit()">
  49. <!--xsl:attribute name="action">/<xsl:value-of select="$Component"/>/<xsl:value-of select="$Command"/></xsl:attribute-->
  50. <input type="hidden" id="component" name="comp" value="{$Component}"/>
  51. <input type="hidden" id="command" name="command" value="{$Command}"/>
  52. <xsl:variable name="componentsDoc" select="document('files/components.xml')"/>
  53. <xsl:if test="not($componentsDoc)">
  54. <xsl:message terminate="yes">Failed to load components.xml.</xsl:message>
  55. </xsl:if>
  56. <xsl:apply-templates select="$componentsDoc/Components/*[name()=$Component]"/>
  57. </form>
  58. </body>
  59. </html>
  60. </xsl:template>
  61. <xsl:template match="Components/*">
  62. <xsl:choose>
  63. <xsl:when test="@caption">
  64. <xsl:if test="string-length(@caption) > 0">
  65. <h1>
  66. <xsl:value-of select="@caption"/>
  67. </h1>
  68. </xsl:if>
  69. </xsl:when>
  70. <xsl:otherwise>
  71. <h1>
  72. <xsl:value-of select="name(.)"/>
  73. </h1>
  74. </xsl:otherwise>
  75. </xsl:choose>
  76. <xsl:variable name="CommandNode" select="Commands/*[name(.)=$Command]"/>
  77. <xsl:if test="not($CommandNode)">
  78. <xsl:message terminate="yes">Command '<xsl:value-of select="$Command"/>' is not defined in components.xml file!"/></xsl:message>
  79. </xsl:if>
  80. <h2>
  81. <xsl:choose>
  82. <xsl:when test="$CommandNode/@caption"><xsl:value-of select="$CommandNode/@caption"/></xsl:when>
  83. <xsl:otherwise><xsl:value-of select="$CommandNode"/></xsl:otherwise>
  84. </xsl:choose>
  85. </h2>
  86. <xsl:call-template name="createXmlFragment">
  87. <xsl:with-param name="CompNode" select="."/>
  88. </xsl:call-template>
  89. <xsl:for-each select="$CommandNode">
  90. <xsl:call-template name="PopulateFormForCommand">
  91. <xsl:with-param name="ArgsNode" select=".//*[name(.)=$ArgsNodeName]"/>
  92. <xsl:with-param name="CreateCancelBtn" select="0"/>
  93. </xsl:call-template>
  94. </xsl:for-each>
  95. </xsl:template>
  96. <xsl:template name="CreateHtmlForm">
  97. <xsl:param name="Component"/>
  98. <xsl:param name="Command"/>
  99. <xsl:param name="FormActionURL"/>
  100. <html>
  101. <head>
  102. <title>
  103. <xsl:value-of select="concat($Command, ' [', $Component, ']')"/>
  104. </title>
  105. </head>
  106. <body>
  107. <h1>
  108. <xsl:value-of select="$Component"/>
  109. </h1>
  110. <h2>
  111. <xsl:value-of select="$Command"/>
  112. </h2>
  113. <form>
  114. <xsl:if test="$FormActionURL">
  115. <attribute name="action">
  116. <xsl:value-of select="$FormActionURL"/>
  117. </attribute>
  118. </xsl:if>
  119. <xsl:apply-templates/>
  120. </form>
  121. </body>
  122. </html>
  123. </xsl:template>
  124. <xsl:template name="DisplayValue">
  125. <xsl:param name="var"/>
  126. <p>
  127. <b>
  128. <xsl:value-of select="name($var)"/>
  129. <xsl:text>: </xsl:text>
  130. <xsl:value-of select="$var"/>
  131. </b>
  132. </p>
  133. </xsl:template>
  134. <xsl:template name="MakeTableHeader">
  135. <xsl:param name="Id" select="table1"/>
  136. <xsl:param name="Columns"/>
  137. <xsl:param name="Border"/>
  138. <xsl:param name="CheckBox" select="0"/>
  139. <xsl:text disable-output-escaping="yes">&lt;table id="</xsl:text>
  140. <xsl:value-of select="$Id"/>
  141. <xsl:text disable-output-escaping="yes">" class="sort-table" border="</xsl:text>
  142. <xsl:value-of select="$Border"/>
  143. <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
  144. <tr>
  145. <xsl:if test="$CheckBox">
  146. <th/>
  147. </xsl:if>
  148. <xsl:for-each select="$Columns/*">
  149. <xsl:call-template name="MakeColumnHeader">
  150. <xsl:with-param name="Column" select="."/>
  151. </xsl:call-template>
  152. </xsl:for-each>
  153. </tr>
  154. </xsl:template>
  155. <xsl:template name="MakeColumnHeader">
  156. <xsl:param name="Column"/>
  157. <xsl:choose>
  158. <!--if the current node has only one child and only occurs once then
  159. its role is simply to group info so use its children instead -->
  160. <xsl:when test="$Column/@maxOccurs='1'">
  161. <xsl:for-each select="$Column/*">
  162. <xsl:call-template name="MakeColumnHeader">
  163. <xsl:with-param name="Column" select="."/>
  164. </xsl:call-template>
  165. </xsl:for-each>
  166. </xsl:when>
  167. <xsl:otherwise>
  168. <th>
  169. <xsl:choose>
  170. <xsl:when test="@caption">
  171. <xsl:value-of select="@caption"/>
  172. </xsl:when>
  173. <xsl:otherwise>
  174. <xsl:value-of select="name(.)"/>
  175. </xsl:otherwise>
  176. </xsl:choose>
  177. </th>
  178. </xsl:otherwise>
  179. </xsl:choose>
  180. </xsl:template>
  181. <xsl:template name="MakeVTableRow">
  182. <xsl:param name="Columns"/>
  183. <tr>
  184. <xsl:for-each select="$Columns/*">
  185. <td>
  186. <xsl:choose>
  187. <xsl:when test="*">
  188. <xsl:apply-templates select="."/>
  189. </xsl:when>
  190. <xsl:otherwise>
  191. <xsl:value-of select="."/>
  192. </xsl:otherwise>
  193. </xsl:choose>
  194. <xsl:apply-templates/>
  195. </td>
  196. </xsl:for-each>
  197. </tr>
  198. </xsl:template>
  199. <xsl:template name="MakeHTableRows">
  200. <xsl:param name="Rows"/>
  201. <xsl:for-each select="$Rows/*">
  202. <tr>
  203. <th align="left" valign="top">
  204. <xsl:choose>
  205. <xsl:when test="@caption">
  206. <xsl:value-of select="@caption"/>
  207. </xsl:when>
  208. <xsl:otherwise>
  209. <xsl:value-of select="name(.)"/>
  210. </xsl:otherwise>
  211. </xsl:choose>
  212. </th>
  213. <th align="left" valign="top">
  214. :
  215. </th>
  216. <td>
  217. <xsl:choose>
  218. <xsl:when test="*">
  219. <table border="0">
  220. <xsl:call-template name="MakeHTableRows">
  221. <xsl:with-param name="Rows" select="."/>
  222. </xsl:call-template>
  223. </table>
  224. </xsl:when>
  225. <xsl:otherwise>
  226. <xsl:value-of select="."/>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </td>
  230. </tr>
  231. </xsl:for-each>
  232. </xsl:template>
  233. <xsl:template name="MakeVerticalTable">
  234. <xsl:param name="Id" select="table1"/>
  235. <xsl:param name="Rows"/>
  236. <xsl:param name="CheckBox" select="0"/>
  237. <xsl:param name="HeaderOnly" select="0"/>
  238. <xsl:param name="AddDelButtons" select="0"/>
  239. <xsl:call-template name="MakeTableHeader">
  240. <xsl:with-param name="Id" select="$Id"/>
  241. <xsl:with-param name="Columns" select="$Rows"/>
  242. <xsl:with-param name="Border" select="1"/>
  243. <xsl:with-param name="CheckBox" select="$CheckBox"/>
  244. </xsl:call-template>
  245. <xsl:if test="($HeaderOnly=0 and $Rows/*)">
  246. <tr>
  247. <xsl:variable name="CheckBoxId" select="concat($Id, 'checkbox')"/>
  248. <td>
  249. <xsl:if test="$CheckBox and normalize-space($Rows/text())">
  250. <input type="checkbox" id="$CheckBoxId" name="$CheckBoxId"/>
  251. </xsl:if>
  252. </td>
  253. <xsl:for-each select="$Rows/*">
  254. <td>
  255. <xsl:choose>
  256. <xsl:when test="*">
  257. <xsl:call-template name="MakeVerticalTable">
  258. <xsl:with-param name="Rows" select="."/>
  259. <xsl:with-param name="CheckBox" select="$CheckBox"/>
  260. <xsl:with-param name="HeaderOnly" select="$HeaderOnly"/>
  261. </xsl:call-template>
  262. </xsl:when>
  263. <xsl:otherwise>
  264. <xsl:if test="$HeaderOnly=0">
  265. <xsl:value-of select="."/>
  266. </xsl:if>
  267. </xsl:otherwise>
  268. </xsl:choose>
  269. </td>
  270. </xsl:for-each>
  271. </tr>
  272. </xsl:if>
  273. <xsl:text disable-output-escaping="yes">&lt;/table&gt;</xsl:text>
  274. <xsl:if test="$AddDelButtons">
  275. <xsl:variable name="ArgsNodeName" select="name($Rows)"/>
  276. <input type="button" id="{$Id}.Add" name="Add" value="Add" onclick="onAdd('{$Id}')"/>
  277. &nbsp;
  278. <input type="button" id="{$Id}.Delete" name="Delete" value="Delete" disabled="true" onclick="onDelete('{$Id}')"/>
  279. </xsl:if>
  280. </xsl:template>
  281. <xsl:template name="MakeCheckbox">
  282. <xsl:param name="CheckboxName"/>
  283. <xsl:param name="Id"/>
  284. <xsl:param name="Checked"/>
  285. <input type="checkbox" id="{$Id}" name="{$CheckboxName}" onclick="this.value=1-this.value;">
  286. <xsl:choose>
  287. <xsl:when test="$Checked=1">
  288. <xsl:attribute name="checked">true</xsl:attribute>
  289. <xsl:attribute name="value">1</xsl:attribute>
  290. </xsl:when>
  291. <xsl:otherwise>
  292. <xsl:attribute name="value">0</xsl:attribute>
  293. </xsl:otherwise>
  294. </xsl:choose>
  295. </input>
  296. </xsl:template>
  297. <xsl:template name="MakeDropDownFileList">
  298. <xsl:param name="Name"/>
  299. <xsl:param name="Id"/>
  300. <xsl:param name="PathName"/>
  301. <xsl:param name="FileExtension"/>
  302. <xsl:param name="Selected"/>
  303. <xsl:param name="onchange"/>
  304. <xsl:variable name="Directory" select="external:Base64Encryption('directory', $PathName, $FileExtension)"/>
  305. <select id="$Id" name="$Name" onchange="{$onchange}">
  306. <xsl:for-each select="$Directory/*">
  307. <xsl:variable name="FilePathName" select="concat($PathName, '/', .)"/>
  308. <option value="$FilePathName">
  309. <xsl:value-of select="$FilePathName"/>
  310. </option>
  311. </xsl:for-each>
  312. </select>
  313. </xsl:template>
  314. <xsl:template name="MakeEditable">
  315. <xsl:param name="InputName"/>
  316. <xsl:param name="Id"/>
  317. <xsl:param name="InputValue"/>
  318. <xsl:param name="dataType"/>
  319. <xsl:choose>
  320. <xsl:when test="not($dataType)">
  321. <INPUT type="text" size="30" id="{$Id}" name="{$InputName}" value="{$InputValue}"/>
  322. </xsl:when>
  323. <xsl:when test="$dataType='boolean'">
  324. <xsl:call-template name="MakeCheckbox">
  325. <xsl:with-param name="CheckboxName" select="$InputName"/>
  326. <xsl:with-param name="Checked" select="$InputValue"/>
  327. <xsl:with-param name="Id" select="checkBox"/>
  328. </xsl:call-template>
  329. </xsl:when>
  330. <xsl:when test="$dataType='text'">
  331. <textarea rows="30" cols="80" id="{$Id}" name="{$InputName}">
  332. <xsl:value-of select="$InputValue"/>
  333. </textarea>
  334. </xsl:when>
  335. <xsl:when test="$dataType='file'">
  336. <INPUT type="file" size="30" id="{$Id}" name="{$InputName}" value="{$InputValue}"/>
  337. </xsl:when>
  338. <xsl:when test="$dataType='editablefile'">
  339. <xsl:variable name="DropDownListName" select="concat('select', '{$InputName}')"/>
  340. <xsl:variable name="Quote">'</xsl:variable>
  341. <xsl:call-template name="MakeDropDownFileList">
  342. <xsl:with-param name="Name" select="$DropDownListName"/>
  343. <xsl:with-param name="Id" select="$DropDownListName"/>
  344. <xsl:with-param name="PathName" select="'DMS/Blobs'"/>
  345. <xsl:with-param name="FileExtension" select="'*.xml'"/>
  346. <xsl:with-param name="Selected" select="none"/>
  347. <xsl:with-param name="onchange" select="concat('loadXmlInTextArea(options[selectedIndex].text, ', $Quote, $InputName, $Quote, ')')"/>
  348. </xsl:call-template>
  349. <br/>
  350. <textarea rows="15" cols="60" id="{$Id}" name="{$InputName}" wrap="off">
  351. <xsl:copy-of select="document($InputValue)"/>
  352. </textarea>
  353. </xsl:when>
  354. <xsl:when test="$dataType='password'">
  355. <INPUT type="password" size="30" id="{$Id}" name="{$InputName}" value="{$InputValue}"/>
  356. </xsl:when>
  357. <xsl:otherwise>
  358. </xsl:otherwise>
  359. </xsl:choose>
  360. </xsl:template>
  361. <xsl:template name="MakeEditableTable">
  362. <xsl:param name="argNode"/>
  363. <xsl:param name="border" select="0"/>
  364. <xsl:param name="OnClickOKBtn" select="''"/>
  365. <xsl:param name="CreateCancelBtn"/>
  366. <table id="ArgumentsTable" name="ArgumentsTable" border="{$border}">
  367. <xsl:variable name="numArgs">
  368. <xsl:choose>
  369. <xsl:when test="count($argNode/*) = 1 and $argNode/*[1]/@maxOccurs='1'">
  370. <xsl:value-of select="count($argNode/*[1]/*)"/>
  371. </xsl:when>
  372. <xsl:otherwise><xsl:value-of select="count($argNode/*)"/></xsl:otherwise>
  373. </xsl:choose>
  374. </xsl:variable>
  375. <xsl:for-each select="$argNode/*">
  376. <xsl:variable name="InputName">
  377. <xsl:value-of select="name(.)"/>
  378. </xsl:variable>
  379. <xsl:variable name="InputValue">
  380. <xsl:value-of select="@default"/>
  381. </xsl:variable>
  382. <tr>
  383. <xsl:if test="$numArgs > 1">
  384. <th align="left" valign="top">
  385. <xsl:value-of select="name(.)"/>
  386. </th>
  387. <th valign="top">
  388. <xsl:text>: </xsl:text>
  389. </th>
  390. </xsl:if>
  391. <td>
  392. <xsl:choose>
  393. <xsl:when test="@maxOccurs='unbounded'">
  394. <xsl:call-template name="MakeVerticalTable">
  395. <xsl:with-param name="Id" select="name(.)"/>
  396. <xsl:with-param name="Rows" select="."/>
  397. <xsl:with-param name="CheckBox" select="1"/>
  398. <xsl:with-param name="HeaderOnly" select="1"/>
  399. <xsl:with-param name="AddDelButtons" select="1"/>
  400. </xsl:call-template>
  401. </xsl:when>
  402. <xsl:otherwise>
  403. <xsl:call-template name="MakeEditable">
  404. <xsl:with-param name="InputName" select="$InputName"/>
  405. <xsl:with-param name="Id" select="$InputName"/>
  406. <xsl:with-param name="InputValue" select="$InputValue"/>
  407. <xsl:with-param name="dataType" select="@dataType"/>
  408. </xsl:call-template>
  409. </xsl:otherwise>
  410. </xsl:choose>
  411. </td>
  412. </tr>
  413. </xsl:for-each>
  414. <!--create vertical space before reset/ok/cancel buttons-->
  415. <tr>
  416. <td style="height:40px">
  417. <xsl:if test="$numArgs > 1">
  418. <xsl:attribute name="colspan">3</xsl:attribute>
  419. </xsl:if>
  420. </td>
  421. </tr>
  422. <!-- create the buttons now-->
  423. <tr>
  424. <td align="center">
  425. <xsl:if test="$numArgs > 1">
  426. <xsl:attribute name="colspan">3</xsl:attribute>
  427. </xsl:if>
  428. <input type="reset" value="Reset"/>&nbsp;&nbsp;&nbsp;
  429. <xsl:call-template name="CreateOKButton">
  430. <xsl:with-param name="OnClickOKBtn" select="$OnClickOKBtn"/>
  431. </xsl:call-template>
  432. <xsl:if test="$CreateCancelBtn">
  433. &nbsp;
  434. <input type="button" id="Cancel" name="Cancel" value="Cancel" onclick="OnCancel()"/>
  435. </xsl:if>
  436. </td>
  437. </tr>
  438. </table>
  439. </xsl:template>
  440. <xsl:template name="PopulateFormForCommand">
  441. <xsl:param name="ArgsNode"/>
  442. <xsl:param name="OnClickOKBtn" select="''"/>
  443. <xsl:param name="CreateCancelBtn" select="1"/>
  444. <xsl:choose>
  445. <xsl:when test="$ArgsNode/*">
  446. <xsl:call-template name="MakeEditableTable">
  447. <xsl:with-param name="argNode" select="$ArgsNode"/>
  448. <xsl:with-param name="OnClickOKBtn" select="$OnClickOKBtn"/>
  449. <xsl:with-param name="CreateCancelBtn" select="$CreateCancelBtn"/>
  450. </xsl:call-template>
  451. </xsl:when>
  452. <xsl:otherwise>
  453. <xsl:call-template name="CreateOKButton">
  454. <xsl:with-param name="OnClickOKBtn" select="$OnClickOKBtn"/>
  455. </xsl:call-template>
  456. </xsl:otherwise>
  457. </xsl:choose>
  458. </xsl:template>
  459. <xsl:template name="CreateOKButton">
  460. <xsl:param name="OnClickOKBtn" select="''"/>
  461. <xsl:choose>
  462. <xsl:when test="not($OnClickOKBtn='')">
  463. <input type="button" id="OK" name="OK" value="Submit" onclick="{$OnClickOKBtn}"/>
  464. </xsl:when>
  465. <xsl:otherwise>
  466. <input type="submit" id="OK" name="OK" value="Submit"/>
  467. </xsl:otherwise>
  468. </xsl:choose>
  469. </xsl:template>
  470. <xsl:template name="createXmlFragment">
  471. <xsl:param name="CompNode"/>
  472. <xsl:variable name="XmlFragment">
  473. <xsl:element name="Components">
  474. <xsl:element name="{name($CompNode)}">
  475. <xsl:apply-templates select="$CompNode/Defaults" mode="copy"/>
  476. <xsl:element name="Commands">
  477. <xsl:apply-templates select="$CompNode/Commands/*[name(.)=$Command]" mode="copy"/>
  478. </xsl:element>
  479. </xsl:element>
  480. </xsl:element>
  481. </xsl:variable>
  482. <xml id="xmlSchema">
  483. <xsl:copy-of select="$XmlFragment"/>
  484. </xml>
  485. <input type="hidden" name="xmlArgs" value=""/>
  486. </xsl:template>
  487. <xsl:template match="*|@*" mode="copy">
  488. <xsl:copy>
  489. <xsl:apply-templates select="*|@*|text()" mode="copy"/>
  490. </xsl:copy>
  491. </xsl:template>
  492. <xsl:template match="text()" mode="copy">
  493. <xsl:copy-of select="normalize-space(.)"/>
  494. </xsl:template>
  495. </xsl:stylesheet>