2

ネットワークデバイスからXSLTを使用して一部のXMLデータを変換するのに問題があります。次のxml出力を検討してください...

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.4X27/junos">
    <multi-routing-engine-results>
        <multi-routing-engine-item>
            <re-name>member0</re-name>
            <environment-information
                xmlns="http://xml.juniper.net/junos/11.4X27/junos-chassis">
                <environment-item>
                    <name>PEM 0</name>
                    <class>Temp</class>
                    <status>OK</status>
                    <temperature junos:celsius="30">30 degrees C / 86 degrees F
                    </temperature>
                </environment-item>
                <environment-item>
                    <name>PEM 1</name>
                    <class>Temp</class>
                    <status>OK</status>
                    <temperature junos:celsius="30">30 degrees C / 86 degrees F
                    </temperature>
                </environment-item>
            </environment-information>
        </multi-routing-engine-item>
        <multi-routing-engine-item>
            <re-name>member1</re-name>
            <environment-information
                xmlns="http://xml.juniper.net/junos/11.4X27/junos-chassis">
                <environment-item>
                    <name>PEM 0</name>
                    <class>Temp</class>
                    <status>OK</status>
                    <temperature junos:celsius="25">25 degrees C / 77 degrees F
                    </temperature>
                </environment-item>
                <environment-item>
                    <name>PEM 1</name>
                    <class>Temp</class>
                    <status>OK</status>
                    <temperature junos:celsius="25">25 degrees C / 77 degrees F
                    </temperature>
                </environment-item>
            </environment-information>
        </multi-routing-engine-item>
    </multi-routing-engine-results>
    <cli>
        <banner>{master:member0-re0}</banner>
    </cli>
</rpc-reply>

XSLTの各「environment-item」要素を反復処理するにはどうすればよいですか。私は現在次のようなものを持っています...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:for-each select="rpc-reply/multi-routing-engine-results/multi-routing-engine-item">
                ...
                <xsl:for-each select="./environment-information/environment-item">
                .....
                </xsl:for-each>
            </block>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet> 

ただし、2番目のループに到達すると、コードは機能しません<xsl:for-each select="./environment-information/environment-item">。私はそれが要素とあまりにも関係があるのではないかと思い<environment-information xmlns="http://xml.juniper.net/junos/11.4X27/junos-chassis">ます。

使用すべき特別な構文はありますか?

4

1 に答える 1

2

問題は名前空間にあります。「http://xml.juniper.net/junos/11.4X27/junos-chassis」名前空間にありますenvironment-informationenvironment-itemこれは機能します:

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:a="http://xml.juniper.net/junos/11.4X27/junos-chassis">
  <xsl:template match="/" >
    <root>
    <xsl:for-each select="rpc-reply/multi-routing-engine-results/multi-routing-engine-item">
      <xsl:for-each select="a:environment-information/a:environment-item">
        <whatever></whatever>
      </xsl:for-each>
    </xsl:for-each>
    </root>
  </xsl:template>
</xsl:stylesheet> 

multi-routing-engine-itemフォーカスは要素にあり、そのアイテムに名前を付けるだけで選択できるため、内側のループの前に「./」を付ける必要はありませんenvironment-information(もちろん、名前空間に注意してください)。

于 2012-05-22T07:43:28.987 に答える