If you want to display the entire matched node (or its XML content) in an XSLT template, you have several options depending on whether you want:
- The raw XML of the matched node (including tags).
- Only the text content (ignoring element tags).
- A deep copy of the node (preserving structure).
1. Output the Raw XML of the Matched Node (<xsl:copy-of>)
If you want to dump the entire matched node as XML (including its children), use:
<xsl:template match="some-node">
<xsl:copy-of select="."/> <!-- Outputs the full XML of the matched node -->
</xsl:template>
Example:
If the input is:
<book>
<title>XSLT Guide</title>
<author>John Doe</author>
</book>
And the template matches <book>, the output will be:
<book>
<title>XSLT Guide</title>
<author>John Doe</author>
</book>
2. Output Only the Text Content (<xsl:value-of>)
If you only want the text content (without XML tags), use:
<xsl:template match="some-node">
<xsl:value-of select="."/> <!-- Outputs only text, no tags -->
</xsl:template>
Example:
For the same <book> input, this would output:
XSLT Guide John Doe
(Note: No XML structure, just concatenated text.)
3. Serialize the Node as a String (saxon:serialize() in Saxon)
If you want the XML as a string (e.g., for debugging), use Saxon’s serialize():
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/">
<xsl:template match="some-node">
<xsl:message>
<xsl:text>Matched node: </xsl:text>
<xsl:value-of select="saxon:serialize(.)"/>
</xsl:message>
</xsl:template>
</xsl:stylesheet>
Output (in logs):
Matched node: <book><title>XSLT Guide</title><author>John Doe</author></book>
4. Debugging with <xsl:message> (Show Node in Console)