1

次の基本的な 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>

コンテンツ タイプごとに異なるテンプレートを使用する予定です。テンプレート一致引数とは? contentType フィールドのみが特定の値である場合、ドキュメントの他の子と一致させる方法を理解できませんでした。

4

1 に答える 1

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>

または、おそらくこのようなものですか?

<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>

それらのいずれかがあなたが探しているものでしょうか?

于 2013-03-18T16:22:15.747 に答える