1

次のようなレイアウトの XML ファイルがあります。

<root>
    <node>
        <descriptors>
            <attribute attr="important"/>
        </descriptors>
        <value>
            Some
        </value>
        <value>
            text
        </value>
        <value>
            here.
        </value>
    <node>
</root>

多くのノードがあり、それぞれが要素内のdescriptors要素によって区別されます。これを得るには、テキストを抽出する必要があります。

<element>
    Sometexthere.
</element>

私はxsl変換を持っています:

<xsl:template match="//attribute[@attr='important']">
    <element>
        <xsl:for-each select="../../value">
            <xsl:value-of select="." />
        </xsl:for-each>
    </element>
</xsl:template>

これは代わりに、ファイル内のすべてのvalue要素にすべての要素を書き込むだけです。nodeスコーピングの仕組みがよくわからないと思います(.現在の要素/ノードを指しているが、ループ内の現在の要素/ノードは何かなど)。

これにどのようにアプローチすればよいですか?

編集

私の実際の xsl スタイルシート (私は docx ファイルを変換しています):

<xsl:template match="/">
        <order>
            <xsl:apply-templates/>
        </order>
    </xsl:template> 
    <xsl:template match="/w:document/w:body/w:p[w:pPr/w:pStyle/@w:val='Pealkiri1']">
        <name>
            <xsl:for-each select="w:t">
                <xsl:value-of select="." />
            </xsl:for-each>
        </name>
    </xsl:template>
4

1 に答える 1