xslt模板匹配具有特定属性的子元素值?

tlu*_*lum 1 xml xslt transform

让我们说一个有这个基本的xml文档:

<result name="response" numFound="73" start="0">
    <doc>
        <str name="contentType">Content1</str>
        <str name="content">Some content here</str>
    </doc>
    <doc>
        <str name="contentType">Content2</str>
        <str name="content">Some other content</str>
    </doc>
</result>
Run Code Online (Sandbox Code Playgroud)

我打算为每种内容类型使用不同的模板.什么是模板匹配参数?当只有contentType字段是特定值时,我无法弄清楚如何匹配doc的其他子节点.

JLR*_*she 6

这听起来像你想要的是这样的:

<xsl:template match="doc[str[@name = 'contentType'] = 'Content1']
                     /str[name = 'Content']">
   <!-- Process Content1 content str -->
</xsl:template>

<xsl:template match="doc[str[@name = 'contentType'] = 'Content2']
                     /str[name = 'Content']">
   <!-- Process Content2 content str -->
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

或许这样的事情?

<xsl:template match="doc[str[@name = 'contentType'] = 'Content1']">
   <!-- Process Content1 doc -->
</xsl:template>

<xsl:template match="doc[str[@name = 'contentType'] = 'Content2']">
   <!-- Process Content2 doc -->
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

这些都是你想要的吗?