Phase 4 ยท Reference Material

XSLT Library

Phase 4 extends the XSLT Library with reusable XSLT 1.0 templates and transformation patterns.

Conditional LogicCore TemplatesLoopsModify ValuesNumberingOutputRedactionRemove NodesSortingVariables
Redacted samples: Sensitive names, URLs, IDs, customer values, infrastructure details, and project-specific values have been replaced with generic placeholders.

Identity Transform

Copies the full XML document unless overridden by another template.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

When to use

Use as the base for most XML cleanup transforms.

Notes

Add override templates after the identity template.

Suppress Matching Element

Removes all matching nodes from the output.

<xsl:template match="SensitiveNode"/>

When to use

Use when a field, node, or section must be excluded.

Notes

Make the match specific enough to avoid removing valid nodes.

Replace Element Text

Copies the element name but changes the value.

<xsl:template match="TargetField">
  <xsl:copy>Redacted Value</xsl:copy>
</xsl:template>

When to use

Use for redaction or calculated replacement values.

Notes

This drops attributes unless you also apply templates to @*.

xsl:if

Outputs content only when a condition is true.

<xsl:if test="normalize-space(FieldName) != ''">
  <HasValue>true</HasValue>
</xsl:if>

When to use

Use for simple one-condition output.

Notes

For if/else behavior, use xsl:choose.

xsl:choose

Provides if/elseif/else style branching.

<xsl:choose>
  <xsl:when test="Status = 'Open'">Open</xsl:when>
  <xsl:when test="Status = 'Closed'">Closed</xsl:when>
  <xsl:otherwise>Unknown</xsl:otherwise>
</xsl:choose>

When to use

Use for multiple possible output values.

Notes

Keep conditions readable and ordered from specific to general.

xsl:for-each

Loops through selected nodes.

<xsl:for-each select="Detail">
  <Line>
    <xsl:value-of select="FieldName"/>
  </Line>
</xsl:for-each>

When to use

Use when building a new structure from repeated nodes.

Notes

Prefer apply-templates for larger, template-driven transforms.

Sort Detail Nodes

Sorts repeated nodes by a field.

<xsl:for-each select="Detail">
  <xsl:sort select="SortField" data-type="text" order="ascending"/>
  <xsl:copy-of select="."/>
</xsl:for-each>

When to use

Use when output order matters.

Notes

Sorting text numbers can produce unexpected order.

Value Of

Outputs the string value of a selected node.

<xsl:value-of select="FieldName"/>

When to use

Use for simple field output.

Notes

If multiple nodes match, XPath 1.0 returns the first in document order.

Copy Of

Copies the selected node and its descendants.

<xsl:copy-of select="Detail"/>

When to use

Use for quickly copying a complete subtree.

Notes

Cannot selectively modify descendants inside copy-of.

Set a Variable

Stores a reusable value.

<xsl:variable name="docNumber" select="Header/DocumentNumber"/>
<xsl:value-of select="$docNumber"/>

When to use

Use to avoid repeating long XPath expressions.

Notes

Variables are immutable in XSLT 1.0.

Generate Sequential Number

Outputs a sequence number for the current context.

<xsl:number count="Detail" level="single"/>

When to use

Use for line numbering.

Notes

The count pattern must match the nodes being numbered.

Generic Redaction Template

Replaces sensitive values with a placeholder.

<xsl:template match="CustomerName | EmailAddress | InternalUrl">
  <xsl:copy>&lt;Redacted&gt;</xsl:copy>
</xsl:template>

When to use

Use when preparing reusable documentation samples.

Notes

Keep real values out of the published sample entirely.

Related Topics

Phase 5 adds related-topic guidance to reduce duplicate entries and make reusable patterns easier to find.

RedactedReviewedCanonical