[
Lists Home |
Date Index |
Thread Index
]
I am getting really strange output from this XSL transform.
The output *looks* perfect - however, each character looks as though it was
prodced in UTF-16 (each char is represented in two byes with a leading 00
byte). Also, the files begins with a char 127 and char 126??? I explicitly
set the encoding to UTF-8 but it still doesn't work. Trying to save the
output as a ".sql" and then ruunning it in sqlplus fails.
Anyone have any ideas?
The XSL follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no"/>
<xsl:variable name="digits" select='-01234567809'/>
<xsl:template match="Import">
<xsl:text></xsl:text>
<xsl:for-each select="Row">
<xsl:text> </xsl:text>
<xsl:text>insert into customer_0_A (</xsl:text>
<xsl:for-each select="*">
<xsl:value-of select="name(.)"/>
<xsl:choose><xsl:when
test="position()!=last()"><xsl:text>,</xsl:text></xsl:when></xsl:choose>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>) values (</xsl:text>
<xsl:for-each select="*">
<xsl:choose>
<xsl:when
test="not(contains($digits,substring(normalize-space(.),1,1)))">
<xsl:text>'</xsl:text>
</xsl:when>
</xsl:choose>
<xsl:value-of select="."/>
<xsl:choose><xsl:when
test="not(contains($digits,substring(normalize-space(.),1,1)))"><xsl:text>'<
/xsl:text></xsl:when></xsl:choose>
<xsl:choose><xsl:when
test="position()!=last()"><xsl:text>,</xsl:text></xsl:when></xsl:choose>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>); </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The transform takes the XML (at bottom) and produces insert statements
for Oralce.
The only thing that made this tough was trying to figure out how/when to put
quotes around strings :-)
A snippet of XML file:
<!-- edited with XML Spy v4.3 U (http://www.xmlspy.com) by Cutler, Dan
(private) -->
<?xml-stylesheet type="text/xsl" href="C:\TEMP\CME\test_data_import.xsl"?>
<Import>
<Row>
<CUSTOMER_KEY>2</CUSTOMER_KEY>
<_DATE_MODIFIED> sysdate</_DATE_MODIFIED>
<_LATEST_FLAG> 1</_LATEST_FLAG>
<_NAME_FIRST>Joe</_NAME_FIRST>
<_NAME_LAST>Bloe</_NAME_LAST>
<_GENDER>Male</_GENDER>
<_TITLE>UNKNOWN</_TITLE>
<_ADDRESS>UNKNOWN</_ADDRESS>
<_CITY>UNKNOWN</_CITY>
<_STATE_PROVINCE>UNKNOWN</_STATE_PROVINCE>
<_ZIPCODE>UNKNOWN</_ZIPCODE>
<_COUNTY>UNKNOWN</_COUNTY>
<_COUNTRY>UNKNOWN</_COUNTRY>
...
</Row>
</Import>
|