flat.xsl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?xml
  2. version="1.0"
  3. encoding="utf-8"
  4. ?>
  5. <xsl:stylesheet
  6. version="1.0"
  7. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. >
  9. <xsl:output
  10. method="html"
  11. encoding="utf-8"
  12. omit-xml-declaration="yes"
  13. standalone="no"
  14. indent="no"
  15. media-type="text/xml"
  16. />
  17. <xsl:param name="theme_name" />
  18. <xsl:param name="theme_path" />
  19. <xsl:template match="/">
  20. <ul>
  21. <xsl:for-each select="//item[not(@parent_id) or @parent_id=0]">
  22. <xsl:call-template name="nodes">
  23. <xsl:with-param name="node" select="." />
  24. <xsl:with-param name="theme_path" select="$theme_path" />
  25. <xsl:with-param name="theme_name" select="$theme_name" />
  26. <xsl:with-param name="is_last" select="number(position() = last())" />
  27. </xsl:call-template>
  28. </xsl:for-each>
  29. </ul>
  30. </xsl:template>
  31. <xsl:template name="nodes">
  32. <xsl:param name="node" />
  33. <xsl:param name="theme_path" />
  34. <xsl:param name="theme_name" />
  35. <xsl:param name="is_last" />
  36. <xsl:variable name="children" select="count(//item[@parent_id=$node/attribute::id]) &gt; 0" />
  37. <li>
  38. <xsl:attribute name="class">
  39. <xsl:if test="$is_last = true()"> last </xsl:if>
  40. <xsl:choose>
  41. <xsl:when test="@state = 'open'"> open </xsl:when>
  42. <xsl:when test="$children or @hasChildren"> closed </xsl:when>
  43. <xsl:otherwise> leaf </xsl:otherwise>
  44. </xsl:choose>
  45. <xsl:value-of select="@class" />
  46. </xsl:attribute>
  47. <xsl:for-each select="@*">
  48. <xsl:if test="name() != 'parent_id' and name() != 'hasChildren' and name() != 'class' and name() != 'state'">
  49. <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
  50. </xsl:if>
  51. </xsl:for-each>
  52. <xsl:for-each select="content/name">
  53. <a href="#">
  54. <xsl:attribute name="class"><xsl:value-of select="@lang" /> <xsl:value-of select="@class" /></xsl:attribute>
  55. <xsl:attribute name="style">
  56. <xsl:value-of select="@style" />
  57. <xsl:if test="string-length(attribute::icon) > 0 and $theme_name != 'themeroller'">background-image:url(<xsl:if test="not(contains(@icon,'/'))"><xsl:value-of select="$theme_path" /></xsl:if><xsl:value-of select="@icon" />);</xsl:if>
  58. </xsl:attribute>
  59. <xsl:for-each select="@*">
  60. <xsl:if test="name() != 'style' and name() != 'class'">
  61. <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
  62. </xsl:if>
  63. </xsl:for-each>
  64. <xsl:if test="$theme_name = 'themeroller' and string-length(attribute::icon) > 0">
  65. <ins>
  66. <xsl:attribute name="class">ui-icon <xsl:value-of select="@icon" /></xsl:attribute>
  67. </ins>
  68. </xsl:if>
  69. <xsl:value-of select="." /></a>
  70. </xsl:for-each>
  71. <xsl:if test="$children or @hasChildren">
  72. <ul>
  73. <xsl:for-each select="//item[@parent_id=$node/attribute::id]">
  74. <xsl:call-template name="nodes">
  75. <xsl:with-param name="node" select="." />
  76. <xsl:with-param name="theme_path" select="$theme_path" />
  77. <xsl:with-param name="theme_name" select="$theme_name" />
  78. <xsl:with-param name="is_last" select="number(position() = last())" />
  79. </xsl:call-template>
  80. </xsl:for-each>
  81. </ul>
  82. </xsl:if>
  83. </li>
  84. </xsl:template>
  85. </xsl:stylesheet>