17.10 - Example: XSL Transform on XML Values - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - XML Data Type

Advanced SQL Engine
Teradata Database
Release Number
July 2021
Last Update
Content Type
Programming Reference
Publication ID
English (United States)
Last Update

This example transforms an XML value by calling its XSL transform method with the stylesheet passed as parameter by value:

SELECT customerXML.XSLTTRANSFORM(new XML('<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/Customer">
      <title>Items Ordered</title>
      <table border="1">
         <th>Item ID</th>
         <th>Part Number</th>
         <th>Unit Price</th>
         <th>Total Price</th>
      <xsl:for-each select="Order/Item">
         <td><xsl:value-of select="@ID"/></td>
         <td><xsl:value-of select="Description"/></td>
         <td><xsl:value-of select="PartNumber"/></td>
         <td><xsl:value-of select="Quantity"/></td>
         <td><xsl:value-of select="UnitPrice"/></td>
         <td><xsl:value-of select="Price"/></td>
</xsl:stylesheet>'), '') FROM customer WHERE customerID=1;

The result is an XML document, which is the result of transforming the source XML using the stylesheet.

Here are partial results from the query. The ellipsis (...) is not part of the query results. It indicates that the query returns additional results that are truncated in the example.

customerXML.XSLTTRANSFORM( NEW XML('<?xml version="1.0"?> <x ...
<html><title>Items Ordered</title><body><table border="1"><tr><th>Item ID</th><th>Description</th><th>Part Number</th><th>Qty</th><th>Unit Price</th><th>Total Price</th></tr><tr><td>001</td><td>Motoro ...