0

以下の XML から「LIVE」を取得したいと思います。同様の投稿を読んで、結果として local-name() 関数を使用していますが、どの XSLT を使用しても取得できません。

<?xml version="1.0"?>
<cns:customer xmlns:cns="https://services.cns.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://services.cns.com docs/xsd/customer.xsd">
    <cns:userId>1001</cns:userId>
    <cns:status>LIVE</cns:status>
    <cns:type wholesale="true" suspended="false">W1</cns:type>
    <cns:properties>
        <cns:property>
            <cns:name>Name</cns:name>
            <cns:value>Bob</cns:value>
        </cns:property>
    </cns:properties>
</cns:customer>

これが私が使用しているXSLTです。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" encoding="UTF-8"/>
    <xsl:template match="//*[local-name()='status']/text()">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>

Oxygen アプリケーションを使用してテストしています。プロセッサはSaxon 6.5.5だと思います。

私が得る出力は次のとおりです。

1001
LIVE
W1

    Name
    Bob

ありがとう、ポール

4

2 に答える 2

2

質問に対する最近の編集に基づいて回答してください。

ちょうど使用:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" encoding="UTF-8"/>
    <xsl:template match="//*[local-name()='status']/text()">
        value: <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>

1001、W1 ....などはどのテンプレートとも一致しないため、デフォルトのテンプレートによって処理され、出力にエコーされます。

ここで、名前空間のバージョンも機能するようにします。

<xsl:template match="/c:customer/c:status" xmlns:c="https://services.cns.com">
    value: <xsl:apply-templates select="text()"/>
</xsl:template>
于 2012-05-19T15:02:36.997 に答える
1

名前空間を XSLT プロセッサに登録する必要があります。しかし、何らかの方法で実行できない場合は、次の XPath 式を実行できるはずです。

//*[local-name()="status"]/text()
于 2012-05-19T14:38:25.733 に答える