1

XSLT 1.0 の使用

多対多の属性をフィルタリングすることは可能ですか。つまり、以下の例のようになります: "../../../../fieldmap/field[@name" つまり、"field/@name" を含むフィールドマップとして 1 つ以上の要素属性が存在し、definition/@title と比較していますが、@title を含む定義要素が 1 つ以上存在します。

例:

<xsl:for-each select="../../../../fieldmaps/field[@name=../destination/@title]">

@name を含むフィールドが定義/@title のいずれかに存在する場合、それらのレコードのみを for-each ループ内で処理する必要があります。(現在のように、最初の @title 属性と比較し、すべての fieldmap/field/@name 属性を考慮するだけです)

ありがとう

4

1 に答える 1

2

変数を使用してそれを実現できます。

<xsl:variable name="titles" select="../destination/@title"/>
<!--now "titles" contains a nodeset with all the titles -->
<xsl:for-each select="../../../../fieldmaps/field[@name=$titles]">
<!-- you process each field with a name contained inside the titles nodeset -->
</xsl:for-each>

簡単な例を次に示します。

入力:

<parent>
    <fieldmaps>
        <field name="One"/>
        <field name="Two"/>
        <field name="Three"/>
    </fieldmaps>
    <destinations>
        <destination title="One"/>
        <destination title="Two"/>
    </destinations>
</parent>

テンプレート:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- ++++++++++++++++++++++++++++++++ -->
    <xsl:template match="parent">
        <Results>
            <xsl:variable name="titles" select="destinations/destination/@title"/>
            <xsl:for-each select="fieldmaps/field[@name=$titles]">
                <Result title="{@name}"/>
            </xsl:for-each>
        </Results>
    </xsl:template>
    <!-- ++++++++++++++++++++++++++++++++ -->
</xsl:stylesheet>

出力:

<Results>
    <Result title="One"/>
    <Result title="Two"/>
</Results>

これが役立つことを願っています!

于 2013-06-20T11:41:47.930 に答える