<xsl:text>'</xsl:text>
<xsl:call-template name="sqlApostrophe">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
<xsl:text>'</xsl:text>
</xsl:when>
<xsl:when test="$date = 'true'">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
当然,这个方法仍然存在问题,我们必须遍历XML文件来逐个执行SQL语句,这是一件我最不喜欢的事情。但是,这个问题有别的解决方法:将单独的语句用逗号分隔开来,建立一个复合SQL语句。
我不认为我懒惰,相反我认为自己有效率。究竟这个方法比前一个方法更不易出错。因此只需稍稍做一些改变,主要是转移一些代码,我建立了如列表C所示的XSL式样表。
列表C——高效XSL样式表
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="table"/>
<xsl:param name="textColumns"/>
<xsl:param name="dateColumns"/>
<xsl:includehref="in.xsl"/>
<xsl:includehref="sqlApostrophe.xsl"/>
<!--
Stylesheet:sample.xsl
Creation Date:October 25, 2006
Programmer:Edmond Woychowsky
Purpose:The purpose of this XSL style sheet is to generate multiple SQL insert statements.
Template:match="/"
Creation Date:October 25, 2006
Programmer:Edmond Woychowsky
Purpose:The purpose of this template is to create the outer sql element and invoke the template for the individual INSERT statements.
Update Date:Programmer:Description:
-->
<xsl:template match="/">
<xsl:element name="sql">
<xsl:apply-templates select="//row"/>
</xsl:element>
</xsl:template>
<!--
Template:match="row"
Programmer:Edmond Woychowsky
Purpose:The purpose of this template is to control the creation of the INSERT statements.
Update Date:Programmer:Description:
-->
<xsl:template match="row">
<xsl:value-of select="concat('INSERT INTO ',$table,' (')"/>
<xsl:apply-templates select="*" mode="name"/>
<xsl:text>) VALUES (</xsl:text>
<xsl:apply-templates select="*" mode="value"/>
<xsl:text>)</xsl:text>
</xsl:template>
<!--
Template:match="*" mode="name"
Programmer:Edmond Woychowsky
Purpose:The purpose of this template is to list the column names.
Update Date:Programmer:Description:
-->
<xsl:template match="*" mode="name">
评论加载中…
![]() |