Figure 1 XML Source Document

  <?xml version="1.0"?>
<product title="Essential XML" xmlns="https://awl.com">
  <writer name='Don Box' />
  <writer name='Aaron Skonnard'/>
  <writer name='John Lam'/>
</product>

Figure 2 DOM-based Translation

  import org.w3c.dom.*;
Document transform(Document source) throws Exception {
  String tns = "https://www.develop.com/Schemas/book";
  DOMImplementation dom = source.getImplementation();
  Document target = dom.createDocument(tns, "content", 
                                       null);
  Element sourceRoot = source.getDocumentElement();
  String title = sourceRoot.getAttribute("title");
  Element e1 = target.createElementNS(tns, "name");
  e1.appendChild(target.createTextNode(title));
  target.getDocumentElement().appendChild(e1);
  e1 = target.createElementNS(tns,"contributors");
  boolean bFirst = false;
  for (Node author = sourceRoot.getFirstChild(); 
       author != null; author = author.getNextSibling()) {
    if (author.getNodeType() != Node.ELEMENT_NODE)
      continue;
    String name = ((Element)author).getAttribute("name");
    Element e2 = target.createElementNS(tns, "staff");
    e2.appendChild(target.createTextNode(name));
    if (!bFirst)
      e2.setAttributeNS("", "principal", "true");
    e1.appendChild(e2);
    bFirst = true;
  }
  target.getDocumentElement().appendChild(e1);
  return target;
}

Figure 3 XSLT Translation

  <?xml version="1.0"?>
<content xmlns="https://www.develop.com/Schemas/book"
      xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
      xsl:exclude-result-prefixes='src'
      xsl:version='1.0'
      xmlns:src="https://awl.com">
  <name><xsl:value-of select="/src:product/@title"/></name>
  <contributors>
    <xsl:for-each select='/src:product/src:writer'>
      <xsl:if test='position() = 1' >
        <staff principal='true'
        ><xsl:value-of select="@name"/></staff>
      </xsl:if>
      <xsl:if test='position() > 1'>
        <staff><xsl:value-of select="@name"/></staff>
      </xsl:if>
    </xsl:for-each>
  </contributors>
</content>

Figure 5 XSLT Instructions

Instruction
Syntax
Description
xsl:copy-of
  <xsl:copy-of
 select = expression />
Emits the node-set corresponding to the select expression.
xsl:value-of
  <xsl:value-of
 select = string-expression
 disable-output-escaping = "yes"
 | "no" />
Emits the string corresponding to the select expression.
xsl:if
  <xsl:if
 test = boolean-expression>
 <!- - Content: template - ->
</xsl:if>

Evaluates the template if and only if the test expression evaluates to true.
xsl:choose
  <xsl:choose>
 <!- - Content: (xsl:when+, xsl:otherwise?) - ->
</xsl:choose>
Evaluates the template from the first xsl:when clause whose test expression evaluates to true. If none of the test expressions evaluate to true, then the template contained in the xsl:otherwise clause is evaluated.
xsl:for-each
  <xsl:for-each
 select = node-set-expression>
 <!- - Content: (xsl:sort*, template) - ->
</xsl:for-each>
Evaluates the template against each node in node-set returned by the select expression. The order of evaluation can be influenced using one or more xsl:sorts.
xsl:call-template
  <xsl:call-template
 name = qname>
 <!- - Content: xsl:with-param* - ->
</xsl:call-template>

Invokes the template rule named by name.
xsl:variable
  <xsl:variable
 name = qname 
 select = expression>
 <!- - Content: template - ->
</xsl:variable>

Declares a variable named name and initializes it using the select expression or template.
xsl:text
  <xsl:text
 disable-output-escaping = "yes" | "no">
 <!- - Content: #PCDATA - ->
</xsl:text>
Emits the text found in #PCDATA. Escaping of the five built-in entities is controlled using disable-output-escaping.
xsl:number
  <xsl:number
 level = "single" | "multiple" | "any"
 count = pattern 
 from = pattern 
 value = number-expression 
 format = { string }
 lang = { nmtoken }
 letter-value = { "alphabetic" | "traditional" }
 grouping-separator = { char }
 grouping-size = { number } />
Emits a number based on the XPath number expression found in value.
xsl:copy
  <xsl:copy
 use-attribute-sets = qnames>
 <!- - Content: template - ->
</xsl:copy>
Copies the current context node (and associated namespace nodes) to the result tree fragment.
xsl:apply-templates
  <xsl:apply-templates
 select = node-set-expression 
 mode = qname>
 <!- - Content: (xsl:sort | xsl:with-param)* - ->
</xsl:apply-templates>

Invokes the best-match template rules against the node-set returned by the select expression.
xsl:apply-imports
<xsl:apply-imports />
Promotes the current stylesheet in import precedence.
xsl:message
  <xsl:message
 terminate = "yes" | "no">
 <!- - Content: template - ->
</xsl:message>

Emits a message in a processor-dependent manner.
xsl:fallback
  <xsl:fallback>
 <!- - Content: template - ->
</xsl:fallback>

Evaluates the template when the parent instruction/directive is not supported by the current processor.
xsl:comment
  <xsl:comment>
 <!- - Content: template - ->
</xsl:comment>

Emits an XML comment containing the template as its character data.
xsl:processing-instruction
  <xsl:processing-instruction
 name = { ncname }>
 <!- - Content: template - ->
</xsl:processing-instruction>

Emits an XML processing instruction whose [target] is name and whose [children] are based on template.
xsl:element
  <xsl:element
 name = { qname }
 namespace = { uri-reference }
 use-attribute-sets = qnames>
 <!- - Content: template - ->
</xsl:element>

Emits an XML element whose [local name] is name, whose [namespace URI] is namespace, and whose [children] are based on template.
xsl:attribute
  <xsl:attribute
 name = { qname }
 namespace = { uri-reference }>
 <!- - Content: template - ->
</xsl:attribute>

Emits an XML attribute whose [local name] is name, whose [namespace URI] is namespace, and whose [children] are based on template.

Figure 6 Using Attribute Sets

  <xsl:stylesheet version='1.0'
     xmlns:xsl='https://www.w3.org/1999/XSL/Transform' >
  <xsl:attribute-set name='myAttrs' >
    <xsl:attribute name='a'>a-val</xsl:attribute>
    <xsl:attribute name='b'>b-val</xsl:attribute>
  </xsl:attribute-set>
  <xsl:attribute-set name='yourAttrs' >
    <xsl:attribute name='c'>c-val</xsl:attribute>
  </xsl:attribute-set>
  <xsl:template name='elems2' >
    <xsl:element name='bob' 
         use-attribute-sets='myAttrs yourAttrs' >
      <steve xsl:use-attribute-sets='yourAttrs' />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

Figure 7 Employing xsl:include

  <?xml version='1.0' ?>
<!-- stylesheeta.xsl -->
<xsl:stylesheet version='1.0' 
           xmlns:xsl='https://www.w3.org/1999/XSL/Transform'>
  <xsl:template name='func-a' ><a/></xsl:template>
</xsl:stylesheet>

<?xml version='1.0' ?>
<!-- stylesheetb.xsl -->
<xsl:stylesheet version='1.0' 
           xmlns:xsl='https://www.w3.org/1999/XSL/Transform'>
  <xsl:include href='stylesheeta.xsl' />
  <xsl:template name='func-b' >
    <xsl:call-template name='func-a' />
  </xsl:template>
</xsl:stylesheet>

Figure 8 xsl:import Stylesheets

  <?xml version='1.0' ?>
<!-- root.xsl -->
<xsl:stylesheet version='1.0' 
           xmlns:xsl='https://www.w3.org/1999/XSL/Transform'>
  <xsl:import href='first.xsl' />
  <xsl:import href='second.xsl' />
  <xsl:template name='func-b' >
    <xsl:call-template name='func-a' />
  </xsl:template>
</xsl:stylesheet>

<?xml version='1.0' ?>
<!-- first.xsl -->
<xsl:stylesheet version='1.0' 
           xmlns:xsl='https://www.w3.org/1999/XSL/Transform'>
  <xsl:template name='func-a' ><first/></xsl:template>
</xsl:stylesheet>

<?xml version='1.0' ?>
<!-- second.xsl -->
<xsl:stylesheet version='1.0' 
           xmlns:xsl='https://www.w3.org/1999/XSL/Transform'>
  <xsl:import href='third.xsl' />
  <xsl:template name='func-a' ><second/></xsl:template>
</xsl:stylesheet>

<?xml version='1.0' ?>
<!-- third.xsl -->
<xsl:stylesheet version='1.0' 
           xmlns:xsl='https://www.w3.org/1999/XSL/Transform'>
  <xsl:template name='func-a' ><third/></xsl:template>
</xsl:stylesheet>