Phase 4 ยท Reference Material
XSLT Library
Phase 4 extends the XSLT Library with reusable XSLT 1.0 templates and transformation patterns.
Conditional Logic Core Templates Loops Modify Values Numbering Output Redaction Remove Nodes Sorting Variables
Core Templates XSLT/XML
Identity Transform
Copies the full XML document unless overridden by another template.
Copy <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.
Remove Nodes XSLT/XML
Suppress Matching Element
Removes all matching nodes from the output.
Copy <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.
Modify Values XSLT/XML
Replace Element Text
Copies the element name but changes the value.
Copy <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 @*.
Conditional Logic XSLT/XML
xsl:if
Outputs content only when a condition is true.
Copy <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.
Conditional Logic XSLT/XML
xsl:choose
Provides if/elseif/else style branching.
Copy <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.
Loops XSLT/XML
xsl:for-each
Loops through selected nodes.
Copy <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.
Sorting XSLT/XML
Sort Detail Nodes
Sorts repeated nodes by a field.
Copy <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.
Output XSLT/XML
Value Of
Outputs the string value of a selected node.
Copy <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.
Output XSLT/XML
Copy Of
Copies the selected node and its descendants.
Copy <xsl:copy-of select="Detail"/>
When to use
Use for quickly copying a complete subtree.
Notes
Cannot selectively modify descendants inside copy-of.
Variables XSLT/XML
Set a Variable
Stores a reusable value.
Copy <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.
Numbering XSLT/XML
Generate Sequential Number
Outputs a sequence number for the current context.
Copy <xsl:number count="Detail" level="single"/>
When to use
Use for line numbering.
Notes
The count pattern must match the nodes being numbered.
Redaction XSLT/XML
Generic Redaction Template
Replaces sensitive values with a placeholder.
Copy <xsl:template match="CustomerName | EmailAddress | InternalUrl">
<xsl:copy><Redacted></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.
Redacted Reviewed Canonical