attributes.xslt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  5. xmlns="http://www.w3.org/1999/xhtml"
  6. xmlns:gv="urn:graphviz"
  7. version="1.0">
  8. <xsl:output method="html" />
  9. <xsl:variable name="arguments" select="document('arguments.xml')" />
  10. <xsl:template match="/">
  11. <html>
  12. <head>
  13. <title>Node, Edge and Graph Attributes</title>
  14. <style>
  15. body
  16. {
  17. margin: 0px;
  18. padding: 0px;
  19. overflow: hidden;
  20. font-family: Georgia;
  21. }
  22. code
  23. {
  24. font-family: Courier;
  25. }
  26. a
  27. {
  28. text-decoration: none;
  29. }
  30. a:hover
  31. {
  32. text-decoration: underline;
  33. }
  34. #indices
  35. {
  36. position: absolute;
  37. left: 0px;
  38. width: 200px;
  39. top: 0px;
  40. bottom: 0px; /* IE doesn't use this */
  41. height: expression(offsetParent.offsetHeight); /* only IE uses this */
  42. overflow: auto;
  43. background: #EEEEEE
  44. }
  45. #contents
  46. {
  47. position: absolute;
  48. left: 210px;
  49. right:0px; /* IE doesn't use this */
  50. width: expression(offsetParent.offsetWidth-210); /* only IE uses this */
  51. top: 0px;
  52. bottom: 0px; /* IE doesn't use this */
  53. height: expression(offsetParent.offsetHeight); /* only IE uses this */
  54. overflow: auto;
  55. }
  56. .val
  57. {
  58. font-family: Courier;
  59. color: green;
  60. }
  61. .attr
  62. {
  63. font-family: Courier;
  64. font-weight: bold;
  65. }
  66. .comp
  67. {
  68. }
  69. .layout
  70. {
  71. }
  72. .format
  73. {
  74. }
  75. .note
  76. {
  77. }
  78. .missing
  79. {
  80. color: lightgray;
  81. }
  82. .heading
  83. {
  84. padding-left: 5px;
  85. padding-right: 5px;
  86. padding-top: 10px;
  87. padding-bottom: 2px;
  88. color: gray;
  89. font-weight: bold;
  90. font-size: 60%;
  91. }
  92. .text
  93. {
  94. padding-left: 20px;
  95. padding-bottom: 10px;
  96. padding-right: 10px;
  97. }
  98. .index
  99. {
  100. padding-left: 20px;
  101. padding-right: 5px;
  102. padding-top: 2px;
  103. padding-bottom: 2px;
  104. display: block;
  105. font-size: 80%;
  106. color: blue;
  107. }
  108. .index_selected
  109. {
  110. background: #8888FF;
  111. color: white;
  112. }
  113. .content
  114. {
  115. display: none;
  116. }
  117. .content_selected
  118. {
  119. display: block;
  120. }
  121. </style>
  122. <script>
  123. <xsl:text disable-output-escaping="yes">
  124. var lastSelected = null;
  125. function addClass (element, newClass)
  126. {
  127. if (element)
  128. {
  129. var classes = element.className.split (" ");
  130. for (var i = 0; i &lt; classes.length; ++i)
  131. if (classes [i] == newClass)
  132. break;
  133. if (i == classes.length)
  134. {
  135. classes.push (newClass);
  136. element.className = classes.join (" ");
  137. }
  138. }
  139. }
  140. function removeClass (element, oldClass)
  141. {
  142. if (element)
  143. {
  144. var classes = element.className.split (" ");
  145. for (var i = 0; i &lt; classes.length; ++i)
  146. if (classes [i] == oldClass)
  147. {
  148. classes.splice (i, 1);
  149. element.className = classes.join (" ");
  150. break;
  151. }
  152. }
  153. }
  154. function select (selected)
  155. {
  156. if (selected != lastSelected)
  157. {
  158. // deselect the last selection
  159. if (lastSelected)
  160. {
  161. removeClass (document.getElementById ("index_" + lastSelected.replace (':', '_')), "index_selected");
  162. removeClass (document.getElementById ("content_" + lastSelected.replace (':', '_')), "content_selected");
  163. }
  164. lastSelected = selected;
  165. var selectedIndex = document.getElementById ("index_" + lastSelected.replace (':', '_'));
  166. addClass (selectedIndex, "index_selected");
  167. // ensure selected index is visible in indices source list
  168. if (selectedIndex)
  169. {
  170. var indexTop = selectedIndex.offsetTop;
  171. var indexBottom = indexTop + selectedIndex.offsetHeight;
  172. var indicesTop = selectedIndex.offsetParent.scrollTop;
  173. var indicesBottom = indicesTop + selectedIndex.offsetParent.offsetHeight;
  174. if (indexBottom &lt; indicesTop || indexTop &gt; indicesBottom)
  175. selectedIndex.scrollIntoView ();
  176. }
  177. // display the content associated with the selected index
  178. addClass (document.getElementById ("content_" + lastSelected.replace (':', '_')), "content_selected");
  179. }
  180. return true;
  181. }
  182. function hashed ()
  183. {
  184. // check if we navigated to a new internal location e.g. via the back button
  185. // if so we need to update the selection
  186. // NOTE: this means there are no real anchors in the HTML at all, we're just simulating them
  187. var hash = window.location.hash;
  188. if (hash &amp;&amp; hash.charAt (0) == '#')
  189. select (hash.substr (1));
  190. else
  191. select ("h:introduction");
  192. return true;
  193. }
  194. function clicked (event)
  195. {
  196. // check to see if an internal link was clicked, if so we need to update the selection
  197. // NOTE: this is not strictly necessary since hashed () will catch it but it helps with the responsiveness
  198. var clickedElement = event.target;
  199. if (!clickedElement)
  200. clickedElement = event.srcElement;
  201. switch (clickedElement.tagName)
  202. {
  203. case 'a':
  204. case 'A':
  205. var oldHref = window.location.href;
  206. var oldHash = oldHref.indexOf ('#');
  207. if (oldHash == -1)
  208. oldHash = oldHref.length;
  209. var newHref = clickedElement.href;
  210. var newHash = newHref.indexOf ('#');
  211. if (newHash == -1)
  212. newHash = newHref.length;
  213. if (oldHref.substr (0, oldHash) == newHref.substr (0, newHash))
  214. {
  215. if (newHash &lt; newHref.length)
  216. select (newHref.substr (newHash + 1));
  217. else
  218. select ("h:introduction");
  219. }
  220. break;
  221. }
  222. return true;
  223. }
  224. function loaded ()
  225. {
  226. hashed ();
  227. window.setInterval ("hashed ()", 1000);
  228. return true;
  229. }
  230. </xsl:text>
  231. </script>
  232. </head>
  233. <body onload="return loaded ()" onclick="return clicked (event)">
  234. <div id="indices">
  235. <!-- display all the attribute type names -->
  236. <div class="heading">NOTES</div>
  237. <xsl:for-each select="/xsd:schema/xsd:annotation[@id]">
  238. <a id="index_h_{@id}" class="index note" href="#h:{@id}">
  239. <xsl:value-of select="@id" />
  240. </a>
  241. </xsl:for-each>
  242. <!-- display all the attribute names -->
  243. <div class="heading">ATTRIBUTES</div>
  244. <xsl:for-each select="/xsd:schema/xsd:attribute">
  245. <a id="index_d_{@name}" class="index attr" href="#d:{@name}">
  246. <xsl:value-of select="@name" />
  247. </a>
  248. </xsl:for-each>
  249. <!-- display all the attribute type names -->
  250. <div class="heading">TYPES</div>
  251. <xsl:for-each select="/xsd:schema/xsd:simpleType">
  252. <a id="index_k_{@name}" class="index type" href="#k:{@name}">
  253. <xsl:value-of select="@name" />
  254. </a>
  255. </xsl:for-each>
  256. </div>
  257. <div id="contents">
  258. <!-- note content -->
  259. <xsl:for-each select="/xsd:schema/xsd:annotation[@id]">
  260. <div id="content_h_{@id}" class="content">
  261. <div class="text">
  262. <xsl:apply-templates select="xsd:documentation/*" mode="html" />
  263. </div>
  264. </div>
  265. </xsl:for-each>
  266. <!-- attribute content -->
  267. <xsl:for-each select="/xsd:schema/xsd:attribute">
  268. <div id="content_d_{@name}" class="content">
  269. <!-- display the layouts this attribute applies to -->
  270. <div class="heading">LAYOUTS</div>
  271. <div class="text">
  272. <xsl:variable name="attributeLayouts" select="@gv:layouts" />
  273. <xsl:for-each select="$arguments/xsd:schema/xsd:simpleType[@name='layout']/xsd:restriction/xsd:enumeration">
  274. <span class="layout">
  275. <xsl:attribute name="class">layout <xsl:if test="$attributeLayouts and not(contains(concat(' ',$attributeLayouts,' '),concat(' ',@value,' ')))">missing</xsl:if></xsl:attribute>
  276. <xsl:value-of select="@value" />
  277. </span>
  278. <xsl:text> </xsl:text>
  279. </xsl:for-each>
  280. </div>
  281. <!-- display the components this attribute is used by -->
  282. <div class="heading">COMPONENTS</div>
  283. <div class="text">
  284. <xsl:variable name="attributeName" select="@name" />
  285. <xsl:for-each select="/xsd:schema/xsd:complexType">
  286. <span class="comp">
  287. <xsl:attribute name="class">comp <xsl:if test="not(xsd:attribute[@ref=$attributeName])">missing</xsl:if></xsl:attribute>
  288. <xsl:value-of select="@name" />
  289. </span>
  290. <xsl:text> </xsl:text>
  291. </xsl:for-each>
  292. </div>
  293. <!-- display the formats this attribute can output -->
  294. <div class="heading">FORMATS</div>
  295. <div class="text">
  296. <xsl:choose>
  297. <xsl:when test="@gv:formats">
  298. <span class="format"><xsl:value-of select="@gv:formats" /></span>
  299. </xsl:when>
  300. <xsl:otherwise>
  301. <span class="format missing">all</span>
  302. </xsl:otherwise>
  303. </xsl:choose>
  304. </div>
  305. <!-- display the type of this attribute -->
  306. <div class="heading">TYPE</div>
  307. <div class="text">
  308. <xsl:choose>
  309. <xsl:when test="@type='xsd:anyURI'">
  310. <span class="type">URL</span>
  311. </xsl:when>
  312. <xsl:when test="@type='xsd:boolean'">
  313. <span class="type">bool</span>
  314. </xsl:when>
  315. <xsl:when test="@type='xsd:decimal'">
  316. <span class="type">double</span>
  317. </xsl:when>
  318. <xsl:when test="@type='xsd:integer'">
  319. <span class="type">int</span>
  320. </xsl:when>
  321. <xsl:when test="@type='xsd:string'">
  322. <span class="type">string</span>
  323. </xsl:when>
  324. <xsl:when test="not(contains(@type,':'))">
  325. <a class="type" href="#k:{@type}"><xsl:value-of select="@type" /></a>
  326. </xsl:when>
  327. </xsl:choose>
  328. </div>
  329. <!-- display the attribute default or none if missing -->
  330. <div class="heading">DEFAULT</div>
  331. <div class="text">
  332. <xsl:choose>
  333. <xsl:when test="@default">
  334. <span class="val">
  335. <xsl:value-of select="@default" />
  336. </span>
  337. </xsl:when>
  338. <xsl:otherwise>
  339. <span class="val missing">none</span>
  340. </xsl:otherwise>
  341. </xsl:choose>
  342. </div>
  343. <!-- display the description from the documentation bits -->
  344. <div class="heading">DESCRIPTION</div>
  345. <div class="text">
  346. <xsl:apply-templates select="xsd:annotation/xsd:documentation/*" mode="html" />
  347. </div>
  348. </div>
  349. </xsl:for-each>
  350. <!-- attribute type content -->
  351. <xsl:for-each select="/xsd:schema/xsd:simpleType">
  352. <div id="content_k_{@name}" class="content">
  353. <!-- display the values if this is an enumeration -->
  354. <xsl:if test="xsd:restriction/xsd:enumeration">
  355. <div class="heading">VALUES</div>
  356. <div class="text">
  357. <xsl:for-each select="xsd:restriction/xsd:enumeration">
  358. <span class="val"><xsl:value-of select="@value" /></span>
  359. <xsl:text> </xsl:text>
  360. </xsl:for-each>
  361. </div>
  362. </xsl:if>
  363. <!-- display the description from the documentation bits -->
  364. <div class="heading">DESCRIPTION</div>
  365. <div class="text">
  366. <xsl:apply-templates select="xsd:annotation/xsd:documentation/*" mode="html" />
  367. </div>
  368. </div>
  369. </xsl:for-each>
  370. </div>
  371. </body>
  372. </html>
  373. </xsl:template>
  374. <xsl:template match="html:a[@rel='attr']" mode="html" xmlns:html="http://www.w3.org/1999/xhtml">
  375. <a href="#d:{text()}" class="attr">
  376. <xsl:apply-templates select="@*|node()" mode="html" />
  377. </a>
  378. </xsl:template>
  379. <xsl:template match="html:a[@rel='type']" mode="html" xmlns:html="http://www.w3.org/1999/xhtml">
  380. <a href="#k:{text()}" class="type">
  381. <xsl:apply-templates select="@*|node()" mode="html" />
  382. </a>
  383. </xsl:template>
  384. <xsl:template match="html:a[@rel='note']" mode="html" xmlns:html="http://www.w3.org/1999/xhtml">
  385. <a href="#h:{text()}" class="note">
  386. <xsl:apply-templates select="@*|node()" mode="html" />
  387. </a>
  388. </xsl:template>
  389. <xsl:template match="@*|node()" mode="html">
  390. <xsl:copy>
  391. <xsl:apply-templates select="@*|node()" mode="html" />
  392. </xsl:copy>
  393. </xsl:template>
  394. </xsl:stylesheet>