用XSLT转换XML遇到性能问题,刚学XSLT不会,希望各位指点
XML文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<product>
<id>1</id>
<name>产品1</name>
</product>
<product>
<id>2</id>
<name>产品2</name>
</product>
<product>
<id>3</id>
<name>产品3</name>
</product>
<row>
<orderid>1</orderid>
<customer>客户1</customer>
<product>
<id>1</id>
<qty>100</qty>
</product>
<product>
<id>3</id>
<qty>200</qty>
</product>
</row>
<row>
<orderid>2</orderid>
<customer>客户2</customer>
<product>
<id>2</id>
<qty>234</qty>
</product>
<product>
<id>3</id>
<qty>321</qty>
</product>
</row>
</root>
=========================================
XSLT文件如下:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet>
<xsl:attribute name="ss:Name">Sheet1</xsl:attribute>
<Table>
<Row>
<xsl:for-each select="root/product">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="id"/>
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="name"/>
</Data>
</Cell>
</xsl:for-each>
</Row>
<xsl:for-each select="root/row">
<xsl:variable name="orderid" select="orderid" />
<Row>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="orderid"/>
</Data>
</Cell>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="customer"/>
</Data>
</Cell>
<xsl:for-each select="/root/product">
<xsl:variable name="id" select="id"/>
<Cell>
<Data ss:Type="String">
<xsl:value-of select="/root/row[orderid=$orderid]/product[id=$id]/qty"/>
</Data>
</Cell>
</xsl:for-each>
</Row>
</xsl:for-each>
</Table>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>
=========================================
说明:
product为所有产品列表。
row为客户的一个订单,
按上面的XSLT能转成我想要的效果,但是当row节点多转换就要很长时间
希望各位帮忙!