【发布时间】:2013-06-27 15:01:16
【问题描述】:
我正在尝试优化 xsl,因为修改我的数据需要很长时间。
我的源数据(我无法修改)如下所示:
<catalog>
<product>
<prodid>12345</prodid>
.....
</proudct>
<product_group_map>
<prodid>12345</prodid>
<groupid>2435</groupid>
</product_group_map>
</catalog>
我想在产品中使用这些 groupId。我到目前为止所做的看起来是这样的:
<xsl:variable name="id"><xsl:value-of select="prodid"/></xsl:variable>
<xsl:variable name="grId">
<xsl:for-each select="../product_group_map">
<xsl:if test="prodid = $id">
<xsl:value-of select="groupid"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- the actual print of the values -->
<xsl:value-of select="concat( $id, $separator, $grId)"/>
所以进程运行 O^2。对于 700 万种产品来说,这是不行的。有没有办法以其他方式匹配所需的 groupId ? 我想到了类似的东西:如果 xml 看起来像这样
<catalog>
<product>
<prodid>12345</prodid>
.....
</proudct>
<product_group_map prodId="12345">
<groupid>2435</groupid>
</product_group_map>
</catalog>
我可以像这样使用选择:
<!--allready in product with the path -->
<xsl:variable name="id"><xsl:value-of select="prodid"/></xsl:variable>
<xsl:variable name="groupid"><xsl:value-of select="../product_group_map[@prodid = $prodId]/groupid"/></xsl:variable>
【问题讨论】:
标签: xml xslt xpath xml-parsing