
下面是customer_insertupdate..xls的代码。在这里,我们首先核对一下客户记录在数据库中是否存在,如果不存在,则插入记录。import net.sf.saxon.Transform;
![]()
public class CustomerOrder...{
public void insert()...{
Transform transformData = new Transform();
String[] args = ...{"customer_insert.xml",
"customer_insertupdate.xsl"};
transformData.doTransform(args, null);
}
}
<xsl:variable name="customerid" select="CUSTOMERID"/>
<xsl:variable name="customer-table">
<sql:query connection="$connection" table="customer"
where="CUSTOMERID='{$customerid}'" column="*"
row-tag="CUSTOMERORDER" column-tag="col"/>
</xsl:variable>
![]()
<xsl:if test="count($customer-table//CUSTOMERORDER) = 0">
<sql:insert table="customer" connection="$connection">
<sql:column name="CUSTOMERID" select="CUSTOMERID"/>
<sql:column name="CUSTOMERLASTNAME" select="CUSTOMERLASTNAME"/>
<sql:column name="CUSTOMERFIRSTNAME" select="CUSTOMERFIRSTNAME"/>
<sql:column name="CUSTOMEREMAIL" select="CUSTOMEREMAIL"/>
</sql:insert>
</xsl:if>
上面的xml表示将得到所有ID是123的记录。显然如果想采用这些技术,就必须在程序中动态产生XML文档。customer_query.xsl的内容如下:<?xml version="1.0"?>
<CUSTOMERORDERS>
<CUSTOMERORDER>
<CUSTORDER>
<ORDERID>123</ORDERID>
</CUSTORDER>
</CUSTOMERORDER>
</CUSTOMERORDERS>
<xsl:template match="CUSTOMERORDERS">
<xsl:message>customer_query.xsl :
Connecting to <xsl:value-of select="$database"/>...</xsl:message>
<xsl:message>customer_query.xsl : query records....</xsl:message>
<xsl:apply-templates select="CUSTOMERORDER" mode="Query"/>
<sql:close connection="$connection"/>
</xsl:template>
![]()
<xsl:template match="CUSTOMERORDER" mode="Query">
<xsl:variable name="orderid" select="CUSTORDER/ORDERID"/>
<xsl:variable name="orderitem-table">
<sql:query connection="$connection" table="ORDERITEM" where="ORDERID=
'{$orderid}'" column="*" row-tag="ORDERITEM" column-tag="col"/>
</xsl:variable>
<xsl:message>There are now <xsl:value-of
select="count($orderitem-table//ORDERITEM)"/> orderitems.</xsl:message>
<ORDER>
<xsl:copy-of select="$orderitem-table"/>
</ORDER>
<sql:close connection="$connection"/>
</xsl:template>
| 第1页: 什么是XQuery | 第2页: XQuery API for Java (XQJ)简介 |
| 第3页: 对数据表进行CRUD操作 | |
| 第5页: 总结 |