gethref.xsl 1.5 KB

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