Examples: XSLT_SHRED_BATCH Using a Context Parameter

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

These examples show how a context parameter can be passed to the shredding operation. Currently defaultDatabase is the only supported context parameter.

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.

Populate the staging table used to store the XML source document.

DELETE Input_Docs;
DELETE DefaultValue2;

INSERT INTO Input_Docs VALUES(1, NEW XML('
<Root>
<AllTypes>
 <Numeric>
  <Byteintc>1</Byteintc>
  <Smallintc>100</Smallintc>
  <Floatc>100</Floatc>
  <Decimalc>100</Decimalc>
  <Numberc>1100</Numberc>
 </Numeric>
</AllTypes>
<AllTypes>
 <Numeric>
  <Byteintc>2</Byteintc>
  <Smallintc>200</Smallintc>
  <Intc>200</Intc>
  <Floatc>200</Floatc>
  <Decimalc>200</Decimalc>
  <Numberc>1200</Numberc>
 </Numeric>
</AllTypes>
</Root>'));

Call the XSLT_SHRED_BATCH stored procedure with the stylesheet mapping to shred the XML data stored in the staging input table. The following arguments are used for the call.

  • The queryString is: sel * from xsltuser.Input_Docs
  • 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 sets the defaultDatabase value.
  • The resultCode is returned in :res. A successful operation returns 0.

Take note of the setting for <defaultDatabase>.

CALL TD_SYSXML.XSLT_SHRED_BATCH('sel * from xsltuser.Input_Docs', 
CREATEXML('<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/Root">
<defaultDatabase>dummyuser2</defaultDatabase>
 <Transaction>
  <Insert>
   <Table>
    <dummyuser.DefaultValue2>
     <xsl:for-each select="AllTypes">
      <Row>
       <byteintc genexp="cast(? as byteint)">
        <xsl:value-of select="Numeric/Byteintc"/>
       </byteintc>
       <smallintc ><xsl:value-of select="Numeric/Smallintc"/></smallintc>
       <intc default="120"><xsl:value-of select="Numeric/Intc"/></intc>
       <floatc><xsl:value-of select="Numeric/Floatc"/></floatc>
      </Row>
     </xsl:for-each>
    </dummyuser.DefaultValue2>
   </Table>
  </Insert>
 </Transaction>
</xsl:template>
</xsl:stylesheet>'), 'defaultDatabase=xsltuser',:res);
Result: To view the updated data in the target table, run: SELECT * FROM DefaultValue2;
byteintc  smallintc         intc                  floatc
--------  ---------  -----------  ----------------------
       1        100          120   1.00000000000000E 002
       2        200          200   2.00000000000000E 002

The following is another example using the context parameter.

Populate the staging table used to store the XML source document.

DELETE Input_Docs;
DELETE Offer;

INSERT INTO Input_Docs VALUES(1,
 createxml('<?xml version="1.0"?>
	<Root>
	 <predictixOfferMessage>
		 <Offer><offerid>1000001</offerid></Offer>
		 <mediaBlock>
			 <mediaBlockid>90000000010001</mediaBlockid>
			 <parentofferid>1001</parentofferid>
		 </mediaBlock>
	 </predictixOfferMessage>
	 <predictixOfferMessage>
		 <Offer><offerid>1000002</offerid></Offer>
		 <mediaBlock>
			 <mediaBlockid>90000000010002</mediaBlockid>
			 <parentofferid>1002</parentofferid>
		 </mediaBlock>
	 </predictixOfferMessage>
	</Root>'));

Call the XSLT_SHRED_BATCH stored procedure with the stylesheet mapping to shred the XML data stored in the staging input table. The following arguments are used for the call.

  • The queryString is: SEL id, xmldoc FROM xsltuser.Input_Docs
  • 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 sets the defaultDatabase to xsltuser.
  • The resultCode is returned in :res. A successful operation returns 0.

Take note of the setting for <defaultDatabase>.

CALL TD_SYSXML.XSLT_SHRED_BATCH('SEL id, xmldoc FROM xsltuser.Input_Docs',
createxml('<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/Root">
<defaultDatabase>TestUser</defaultDatabase>
 <Transaction>
  <Insert>
   <Table>
    <Offer>
	    <xsl:for-each select="predictixOfferMessage">
	    <Row>
	     <xsl:copy-of select="Offer/offerid"/>
	     <xsl:copy-of select="mediaBlock/mediaBlockid"/>
	    </Row>
	    </xsl:for-each>
	   </Offer>
   </Table>
  </Insert>
 </Transaction>
</xsl:template>
</xsl:stylesheet>'), 'defaultDatabase=XSLTUSER',:res);
Result: To view the updated data in the target table, run: SELECT offerid, mediaBlockid FROM Offer;
offerid     mediaBlockid
----------  ---------------------
1000001     90000000010001
1000002     90000000010002