Extension Examples

These examples are from James' XT distribution:

Figure 30. ext-func.xsl

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:date="http://www.jclark.com/xt/java/java.util.Date">

<xsl:template match="/">
  <html>
    <xsl:if test="function-available('date:to-string') and function-available('date:new')">
      <p><xsl:value-of select="date:to-string(date:new())"/></p>
    </xsl:if>
  </html>
</xsl:template>

</xsl:stylesheet>


Figure 31. ext-elem.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		version="1.0"
                xmlns:xt="http://www.jclark.com/xt"
                extension-element-prefixes="xt">

<xsl:output method="text"/>

<xsl:template match="file">
  <xt:document href="{@name}" method="xml">
    <xsl:fallback>This should not happen.</xsl:fallback>
    <xsl:apply-templates mode="copy"/>
  </xt:document>
  <xsl:text>Created file </xsl:text>
  <xsl:value-of select="@name"/>
  <xsl:text>&#xA;</xsl:text>
</xsl:template>

<xsl:template mode="copy" match="*|@*">
  <xsl:copy>
    <xsl:apply-templates select="@*" mode="copy"/>
    <xsl:apply-templates select="node()" mode="copy"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>