Expand | Collapse

◀ 13. Indexing of terms15. Display navigation menu ▶

14. XHTML1 pass-through

xsl:stylesheet id="stylesheet" exclude-result-prefixes="x2 lit" version="1.0" xml:lang="en"

    copy-xhtml1: copy an XHTML2 element as an XHTML1 element
    copy @*: copy attributes
    copy-id template: duplicates the ID attribute


14.1. copy-xhtml1: copy an XHTML2 element as an XHTML1 element

This copies a XHTML2 element but changes its XML namespace to XHTML1. This can obviously be done if the given element in XHTML2 has the same semantics as the element of the same name in XHTML1.

The XHTML2 → XHTML1 name mapping is not recursive by default, so that it is possible that translation only for applicable elements and handle the rest of the elements by other templates.

xsl:template name="copy-xhtml1"
      xsl:param name="target" select="."
      xsl:param name="tag-name" select="local-name($target)"
      xsl:param name="content"
        xsl:apply-templates select="$target/node()"
      xsl:element name="{$tag-name}" namespace="http://www.w3.org/1999/xhtml"
        xsl:apply-templates select="@*" mode="copy"
        xsl:copy-of select="$content"

14.2. copy @*: copy attributes

This copies the selected attribute value to the output with no change.

xsl:template match="@*" mode="copy"
        xsl:value-of select="."

14.3. copy-id template: duplicates the ID attribute

This copies only the ID attribute if it exists on the source node. If it does not exist, the ID is generated.

xsl:template name="copy-id"
      xsl:param name="target" select="."
      xsl:attribute name="id"
        xsl:call-template name="id"
          xsl:with-param name="target" select="$target"

Formatted using xhtml2to1 by Steve Cheng.