gethref.xsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!--
  2. This file is part of the DITA Open Toolkit project.
  3. Copyright 2007 Shawn McKenzie
  4. See the accompanying LICENSE file for applicable license.
  5. -->
  6. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  7. <xsl:template name="gethref">
  8. <xsl:param name="ditahref"/>
  9. <xsl:if test="@scope='external' and @format='html'">
  10. <xsl:value-of select="@href"/>
  11. </xsl:if>
  12. <xsl:if test="not(@scope='external')">
  13. <xsl:if test="contains($ditahref, '#')">
  14. <xsl:call-template name="swapext">
  15. <xsl:with-param name="newhref" select="substring-before($ditahref, '#')"/>
  16. </xsl:call-template>
  17. </xsl:if>
  18. <xsl:if test="not(contains($ditahref, '#'))">
  19. <xsl:call-template name="swapext">
  20. <xsl:with-param name="newhref" select="$ditahref"/>
  21. </xsl:call-template>
  22. </xsl:if>
  23. </xsl:if>
  24. </xsl:template>
  25. <xsl:template name="swapext">
  26. <xsl:param name="newhref"/>
  27. <xsl:if test="substring($newhref, string-length($newhref) - string-length('.xml') +1) = '.xml'">
  28. <xsl:value-of select="concat(substring-before($newhref, '.xml'), '.html')"/>
  29. </xsl:if>
  30. <xsl:if
  31. test="substring($newhref, string-length($newhref) - string-length('.dita') +1) =
  32. '.dita'">
  33. <xsl:value-of select="concat(substring-before($newhref, '.dita'), '.html')"/>
  34. </xsl:if>
  35. </xsl:template>
  36. </xsl:stylesheet>