2006-12-08

如何将XML文件中的数据传送并保存在关系数据库中

来源: 开发者在线 作者:佚名 评论 0 条
 

<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">
共4页: 上一页 [1] [2] 3 [4] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:如何从一个php文件向另一个地址post数据,不用表单和隐藏的变量  
下一篇:Mashups:Web 应用程序新成员
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号