xsdattr2htmltable.xsl2 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="2.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  5. xmlns:hpcc="https://www.hpccsystems.com"
  6. exclude-result-prefixes="xs"
  7. >
  8. <xsl:output method="xml" indent="yes" omit-xml-declaration="no" encoding="UTF-8"/>
  9. <xsl:variable name="title" select="xs:schema/xs:element[1]/@name"/>
  10. <xsl:template match="/xs:schema">
  11. <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE sect1 PUBLIC &quot;-//OASIS//DTD DocBook XML V4.5//EN&quot;
  12. &quot;http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd&quot;&gt; </xsl:text>
  13. <sect2>
  14. <xsl:attribute name="id"><xsl:value-of select="$title"/>_mod</xsl:attribute>
  15. <title><xsl:value-of select="$title"/></title>
  16. <xsl:apply-templates select = "//xs:element"/>
  17. <xsl:apply-templates select = "//xs:complexType"/>
  18. <xsl:apply-templates select = "//xs:attributeGroup"/>
  19. </sect2>
  20. </xsl:template>
  21. <xsl:function name = "hpcc:has_attributes_to_process" as = "xs:boolean">
  22. <xsl:param name = "parent" />
  23. <xsl:choose>
  24. <xsl:when test = "count($parent/xs:attribute) gt
  25. count($parent/xs:attribute/xs:annotation/xs:appinfo/viewType/'hidden')">
  26. true
  27. </xsl:when>
  28. <xsl:otherwise>
  29. false
  30. </xsl:otherwise>
  31. </xsl:choose>
  32. </xsl:function>
  33. <xsl:template match="xs:element">
  34. <xsl:if test = "hpcc:has_attributes_to_process(.)">
  35. <xsl:variable name = "index"><xsl:number level="any"/></xsl:variable>
  36. <xsl:call-template name = "element-ancestors"/>
  37. <para><emphasis role="bold">Attributes</emphasis></para>
  38. <xsl:call-template name = "informaltable">
  39. <xsl:with-param name = "undef-id" select = "$index"/>
  40. </xsl:call-template>
  41. </xsl:if>
  42. </xsl:template>
  43. <xsl:template match="xs:complexType">
  44. <xsl:if test = "hpcc:has_attributes_to_process(.)">
  45. <xsl:variable name = "index">CT<xsl:number level="any"/></xsl:variable>
  46. <xsl:call-template name = "element-ancestors"/>
  47. <para><emphasis role="bold">Attributes</emphasis></para>
  48. <xsl:call-template name = "informaltable">
  49. <xsl:with-param name = "undef-id" select = "$index"/>
  50. </xsl:call-template>
  51. </xsl:if>
  52. </xsl:template>
  53. <xsl:template match="xs:attributeGroup">
  54. <xsl:if test = "hpcc:has_attributes_to_process(.)">
  55. <xsl:variable name = "index">AG<xsl:number level="any"/></xsl:variable>
  56. <para><emphasis role="bold"><xsl:value-of select = "@name"/></emphasis></para>
  57. <para><emphasis role="bold"></emphasis></para>
  58. <xsl:call-template name = "informaltable">
  59. <xsl:with-param name = "undef-id" select = "$index"/>
  60. </xsl:call-template>
  61. </xsl:if>
  62. </xsl:template>
  63. <!--ADDED logic here where if successive consecutive <para> elements that they can be joined(see esp3 headings)-->
  64. <xsl:template name = "element-ancestors">
  65. <para><emphasis role="bold">
  66. <xsl:for-each select="ancestor::*">
  67. <xsl:if test = "name() = 'xs:element'">
  68. <xsl:value-of select = "@name"/><xsl:text> </xsl:text>
  69. </xsl:if>
  70. </xsl:for-each>
  71. </emphasis></para>
  72. </xsl:template>
  73. <xsl:template name = "informaltable">
  74. <xsl:param name = "undef-id"/>
  75. <informaltable>
  76. <xsl:attribute name="colsep">1</xsl:attribute>
  77. <xsl:attribute name="rowsep">1</xsl:attribute>
  78. <xsl:choose>
  79. <xsl:when test = "xs:annotation/xs:appinfo/docid">
  80. <xsl:attribute name="id">
  81. <xsl:value-of select="xs:annotation/xs:appinfo/docid"/>
  82. </xsl:attribute>
  83. </xsl:when>
  84. <xsl:otherwise>
  85. <xsl:attribute name="id">UNDEFINED-<xsl:value-of select="$undef-id"/></xsl:attribute>
  86. </xsl:otherwise>
  87. </xsl:choose>
  88. <tgroup cols="4" align="left">
  89. <colspec colwidth="155pt" /><colspec colwidth="2*" /><colspec colwidth="1*" /><colspec colwidth="0.5*" />
  90. <thead>
  91. <row>
  92. <entry>attribute</entry>
  93. <entry>description</entry>
  94. <entry>values</entry>
  95. <entry>required</entry>
  96. </row>
  97. </thead>
  98. <tbody>
  99. <xsl:apply-templates select="xs:attribute"/>
  100. </tbody>
  101. </tgroup>
  102. </informaltable>
  103. </xsl:template>
  104. <xsl:template match = "xs:attribute">
  105. <xsl:variable name="viewType">
  106. <xsl:choose>
  107. <xsl:when test="xs:annotation/xs:appinfo/viewType">
  108. <xsl:value-of select="xs:annotation/xs:appinfo/viewType/text()"/>
  109. </xsl:when>
  110. <xsl:otherwise>visible</xsl:otherwise>
  111. </xsl:choose>
  112. </xsl:variable>
  113. <xsl:variable name="tooltip">
  114. <xsl:choose>
  115. <xsl:when test="xs:annotation/xs:appinfo/tooltip">
  116. <xsl:value-of select="xs:annotation/xs:appinfo/tooltip/text()"/>
  117. </xsl:when>
  118. <xsl:otherwise></xsl:otherwise>
  119. </xsl:choose>
  120. </xsl:variable>
  121. <xsl:variable name="use">
  122. <xsl:choose>
  123. <xsl:when test="xs:annotation/xs:appinfo/required">
  124. <xsl:value-of select="xs:annotation/xs:appinfo/required/text()"/>
  125. </xsl:when>
  126. <xsl:when test="@use">
  127. <xsl:value-of select="@use"/>
  128. </xsl:when>
  129. <xsl:otherwise>optional</xsl:otherwise>
  130. </xsl:choose>
  131. </xsl:variable>
  132. <xsl:variable name="use2">
  133. <xsl:choose>
  134. <xsl:when test="$use = 'true'">required</xsl:when>
  135. <xsl:when test="$use = 'required'">required</xsl:when>
  136. <xsl:otherwise>optional</xsl:otherwise>
  137. </xsl:choose>
  138. </xsl:variable>
  139. <xsl:if test="$viewType != 'hidden'">
  140. <row>
  141. <entry><xsl:value-of select="@name"/></entry>
  142. <entry><xsl:value-of select="$tooltip"/></entry>
  143. <entry><xsl:value-of select="@default"/></entry>
  144. <entry><xsl:value-of select="$use2"/></entry>
  145. </row>
  146. </xsl:if>
  147. </xsl:template>
  148. </xsl:stylesheet>