mapwalker.xsl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2004, 2005 IBM Corporation
  5. See the accompanying LICENSE file for applicable license.
  6. -->
  7. <!-- write technique adapted from Norman Walsh's DocBook XSLT
  8. first instance technique adapted from Jeni Tennison and Steve Muench -->
  9. <xsl:stylesheet version="2.0"
  10. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  11. <!-- stylesheet imports -->
  12. <xsl:key name="topicref"
  13. match="*[contains(@class, ' map/topicref ')]"
  14. use="@href"/>
  15. <xsl:template match="/">
  16. <xsl:apply-templates select="*[contains(@class,' map/map ')]"/>
  17. </xsl:template>
  18. <xsl:template match="*[contains(@class,' map/map ')]">
  19. <xsl:apply-templates select="*[contains(@class,' map/topicref ')]"/>
  20. </xsl:template>
  21. <xsl:template match="*[contains(@class,' map/topicref ')]">
  22. <xsl:param name="infile" select="@href"/>
  23. <xsl:param name="outroot">
  24. <xsl:choose>
  25. <xsl:when test="contains($infile, '.xml')">
  26. <xsl:value-of select="substring-before($infile, '.xml')"/>
  27. </xsl:when>
  28. <xsl:when test="contains($infile, '.dita')">
  29. <xsl:value-of select="substring-before($infile, '.dita')"/>
  30. </xsl:when>
  31. <xsl:otherwise>
  32. <xsl:value-of select="$infile"/>
  33. </xsl:otherwise>
  34. </xsl:choose>
  35. </xsl:param>
  36. <xsl:param name="outfile">
  37. <xsl:choose>
  38. <xsl:when test="contains($infile, '.xml') or contains($infile, '.dita')">
  39. <xsl:value-of select="concat($outroot, $OUTEXT)"/>
  40. </xsl:when>
  41. <xsl:otherwise>
  42. <xsl:value-of select="$infile"/>
  43. </xsl:otherwise>
  44. </xsl:choose>
  45. </xsl:param>
  46. <xsl:param name="nodeID" select="generate-id(.)"/>
  47. <xsl:param name="isFirstFile">
  48. <xsl:choose>
  49. <xsl:when test="$infile and $infile!=''">
  50. <xsl:value-of
  51. select="$nodeID = generate-id(key('topicref', $infile)[1])"/>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <xsl:value-of select="true()"/>
  55. </xsl:otherwise>
  56. </xsl:choose>
  57. </xsl:param>
  58. <xsl:param name="isFirst" select="string($isFirstFile)='true'"/>
  59. <xsl:apply-templates select="." mode="process">
  60. <xsl:with-param name="infile" select="@href"/>
  61. <xsl:with-param name="outroot" select="$outroot"/>
  62. <xsl:with-param name="outfile" select="$outfile"/>
  63. <xsl:with-param name="nodeID" select="$nodeID"/>
  64. <xsl:with-param name="isFirst" select="$isFirst"/>
  65. </xsl:apply-templates>
  66. </xsl:template>
  67. <!-- required overrides -->
  68. <xsl:template match="*[contains(@class,' map/topicref ')]" mode="process">
  69. <xsl:param name="infile"/>
  70. <xsl:param name="outroot"/>
  71. <xsl:param name="outfile"/>
  72. <xsl:param name="nodeID"/>
  73. <xsl:param name="isFirst"/>
  74. <xsl:message terminate="yes">
  75. <xsl:text>no process rule for topicref</xsl:text>
  76. </xsl:message>
  77. </xsl:template>
  78. </xsl:stylesheet>