17.10 - Mapping SQL Query Results to an XML Format - 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

You can create an XSLT stylesheet that provides a mapping definition describing how an SQL query result is mapped to an XML tree structure. XSLT (eXtensible Stylesheet Language Transformation) is the language used for describing transformations from one XML structure to another or to other text formats. For XML publishing, use the mapping stylesheet to define a transformation from the canonical XML representation of a query result to the desired XML structure.

The following is an example of an XSLT mapping for publishing the results of the query shown in the previous section. The example defines a transformation from the canonical XML representation. For example, the xsl:for-each instruction constructs a customer element for each Row element in the canonical XML representation.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:template match="/">
         <xsl:for-each select="QuerySchema/ROW">
            <customer teradata_group="CUSTID">
                  <xsl:value-of select="CUSTID"/>
                  <xsl:value-of select="CNAME"/>
                  <xsl:value-of select="ACCTID"/>
                  <xsl:value-of select="ANAME"/>
                  <xsl:value-of select="ORDERID"/>
                  <xsl:value-of select="ODATE"/>
                  <xsl:value-of select="REPID"/>
                  <xsl:value-of select="REPNAME"/>
                  <xsl:value-of select="ITEMID"/>
                  <xsl:value-of select="QTY"/>