如何在XSL匹配模板标记中使用xsi:type属性

时间:2017-05-19 03:27:49

标签: xml xslt

这是我的xml文件:

<products>
<product xsi:type="Styles" locale="en_US">
<pageid>abcdef</pageid>
<totalStyles>4</totalStyles>
</product>
<product xsi:type="Styles" locale="en_CA">
<pageid>abcdef</pageid>
<totalStyles>2</totalStyles>
</product>
</products>

XSL代码:

<xsl:template match="products/product">
        <xsl:value-of select="pageid" />
</xsl:template>

如xml文件中所列,我有两个具有相同pageid的“product”标记,但具有不同的“locale”值。 我想过滤'locale'并检索仅对应于locale = en_US的'totalStyles'标记值。 有人可以建议我如何修改我的模板匹配来过滤语言环境值。

以下代码在xsi:type不退出时有效。但是,这种方法失败了,我有xsi:type组件和locale。

<xsl:template match="products/product[@locale='en_US']">
    <xsl:value-of select="totalStyles"/>
</xsl:template>

提前致谢。

很抱歉,如果我没有正确地提出问题。

2 个答案:

答案 0 :(得分:0)

<xsl:template match="products/product[@locale='en_US']">
    <xsl:value-of select="totalStyles"/>
</xsl:template>

答案 1 :(得分:-1)

我使用以下逻辑来过滤属性值:

<xsl:template match="products/product">
<xsl:if test="@locale='en_US'">

      "Process Record"

</xsl:if>
相关问题