specialize.xsl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?xml version="1.0" encoding="UTF-8" ?>
  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 IBM Corp. 2004, 2005 All Rights Reserved. -->
  6. <!-- specialize.xsl
  7. | Convert "generalized" DITA topics back into specialized form
  8. *-->
  9. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  10. <xsl:output method="xml" indent="no"/>
  11. <!--Find the class attribute within the XML instance document. -->
  12. <xsl:template match="*[@class]">
  13. <xsl:call-template name="specialize">
  14. <xsl:with-param name="class" select="@class"/>
  15. </xsl:call-template>
  16. </xsl:template>
  17. <!--Look for the last class definition, i.e, task/steps. Replace existing generalized element name
  18. with specialized element name -->
  19. <xsl:template name="specialize">
  20. <xsl:param name="class"/>
  21. <xsl:choose>
  22. <xsl:when test="contains(normalize-space($class),' ')">
  23. <xsl:call-template name="specialize">
  24. <xsl:with-param name="class" select="substring-after($class,' ')"/>
  25. </xsl:call-template>
  26. </xsl:when>
  27. <xsl:otherwise>
  28. <xsl:variable name="element_name" select="substring-after(normalize-space($class),'/')" />
  29. <xsl:element name="{$element_name}">
  30. <xsl:copy-of select="@*[local-name() != 'class']"/>
  31. <xsl:apply-templates/>
  32. </xsl:element>
  33. </xsl:otherwise>
  34. </xsl:choose>
  35. </xsl:template>
  36. <!--pick up everything from the element -->
  37. <xsl:template match="*|@*|comment()|processing-instruction()|text()">
  38. <xsl:copy>
  39. <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
  40. </xsl:copy>
  41. </xsl:template>
  42. <xsl:template match="*[contains(@class,' topic/object ')][@data and not(@data='')][@type='DITA-foreign']" priority="10">
  43. <xsl:apply-templates select="document(@data,/)/*/*" mode="specialize-foreign-unknown"/>
  44. </xsl:template>
  45. <xsl:template match="*|@*|text()|comment()|processing-instruction()" mode="specialize-foreign-unknown">
  46. <xsl:copy>
  47. <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="specialize-foreign-unknown"/>
  48. </xsl:copy>
  49. </xsl:template>
  50. </xsl:stylesheet>