Example: XSLT_SHRED Usage Example

Teradata Vantageā„¢ XML Data Type

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1140-162K

This example shows how to use XSLT_SHRED.

Before running the example, ensure the test user is created with the required permissions and the required tables are created. See Setting Up the XSLT_SHRED_BATCH and XSLT_SHRED Examples for details.

Call the XSLT_SHRED stored procedure to shred the XML document. The following arguments are used for the call.

  • The xmlDoc is created automatically in this example with the NEW XML statement.
  • The xsltMapping argument is supplied by invoking the CREATEXML function with a stylesheet as input. This stylesheet will be applied to the XML document.
  • The externalContext is NULL.
  • The resultCode is returned in :res. A successful operation returns 0.
CALL TD_SYSXML.XSLT_SHRED(NEW XML(
'<Root>
 <AllTypes>
  <DateTime>
   <Datec>2000-09-09</Datec>
   <Timec>12:12:12</Timec>
   <Timewzc>12:12:12+00:00</Timewzc>
   <TimeStampc>2000-09-09T12:12:12</TimeStampc>
   <TimeStampwzc>2000-09-09T12:12:12+00:00</TimeStampwzc>
  </DateTime>
 </AllTypes>
 <AllTypes>
  <DateTime>
   <Datec>2000-09-10</Datec>
   <Timec>12:12:12</Timec>
   <Timewzc>12:12:12+00:00</Timewzc>
   <TimeStampc>2000-09-09T12:12:12</TimeStampc>
  </DateTime>
 </AllTypes>
 </Root>'),
	CREATEXML('<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:date="http://exslt.org/dates-and-times"  
extension-element-prefixes="date" version="1.0" >
<xsl:param name="XML_TimeStamp" select="date:date-time()"/>
<xsl:template match="/Root">
 <Transaction>
  <Insert>
   <Table>
    <xsltuser.DefaultValue4>
     <xsl:for-each select="AllTypes">
      <Row>
       <C_Datec genexp="(? as Date)"><xsl:value-of select="DateTime/Datec"/></C_Datec>
       <C_Timec genexp="(? as Time(6))">
          <xsl:value-of select="DateTime/Timec"/></C_Timec>
       <C_Timewzc genexp="(? as Time(6) WITH TIME ZONE)">
          <xsl:value-of select="DateTime/Timewzc"/></C_Timewzc>
       <C_TimeStampc genexp="(? as TIMESTAMP(6))">
          <xsl:value-of select="DateTime/TimeStampc"/></C_TimeStampc>
       <C_TimeStampwzc genexp="(? as TIMESTAMP(6) WITH TIME ZONE)" default="{$XML_TimeStamp}">
          <xsl:value-of select="DateTime/TimeStampwzc"/></C_TimeStampwzc>
      </Row>
     </xsl:for-each>
    </xsltuser.DefaultValue4>
   </Table>
  </Insert>
 </Transaction>
</xsl:template>
</xsl:stylesheet>'), '',:res);
Result: To view the updated data in the target table, run: SELECT * FROM DefaultValue4;
C_Datec C_Timec C_Timewzc C_TimeStampc

C_TimeStampwzc

00/09/10 12:12:12.000000 12:12:12.000000+00:00 2000-09-09 12:12:12.000000

2014-05-07 05:08:17.000000-04:00

00/09/09 12:12:12.000000 12:12:12.000000+00:00 2000-09-09 12:12:12.000000 2000-09-09 12:12:12.000000+00:00