【发布时间】:2014-05-22 22:03:35
【问题描述】:
我需要 XSLT 方面的帮助...在输入 xml 中,我有:
<shop>
<categories>
<category categoryId="63" parentCategoryId="239">
<name>Fruit</name>
</category>
<category categoryId="62" parentCategoryId="239">
<name>Vegetable</name>
</category>
<category categoryId="60" parentCategoryId="221">
<name>Furniture</name>
</category>
...
<categories>
<products>
<product productId="3" productCode="1.05">
<name>Chair</name>
<categories>
<category>60</category>
</categories>
</product>
<product productId="21" productCode="1.59">
<name>Apple</name>
<categories>
<category>63</category>
</categories>
</product>
...
</products>
</shop>
我需要创建产品列表,其中包含产品名称及其类别名称。我怎样才能做到这一点?这对我不起作用...
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="shop">
<export>
<xsl:apply-templates select="products" />
</export>
</xsl:template>
<xsl:template match="products">
<xsl:for-each select="product">
<polozka>
<product_name>
<xsl:value-of select="name" />
</product_name>
<xsl:for-each select="/shop/categories/category">
<xsl:if test="boolean(@categoryId = /shop/products/product/categories/category)">
<category_name>
<xsl:value-of select="name" />
</category_name>
</xsl:if>
</xsl:for-each>
</polozka>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如果有人可以帮助我,我会很高兴...
【问题讨论】:
-
你能添加一个你期望输出的样本吗?谢谢!
标签: xml xslt if-statement compare