2

私はこのxmlファイルを持っています

<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="file:/dev/null" iosp="lasp.tss.iosp.ValueGeneratorIOSP" start="0" increment="1">
    <attribute name="title" value="Vector time series"/>
    <dimension name="time" length="100"/>
    <variable name="time" shape="time" type="double">
        <attribute name="units" type="String" value="seconds since 1970-01-01T00:00"/>
    </variable>
    <group name="Vector" tsdsType="Structure" shape="time">
        <variable name="x" shape="time" type="double"/>
        <variable name="y" shape="time" type="double"/>
        <variable name="z" shape="time" type="double"/>
    </group>
</netcdf>

そして、このような出力を与えるxsltファイルが必要です

1.time
2.Vector

variable と group の 2 つのタグの name 属性です。現在、私はこのようなコードを持っています

 <xsl:for-each select="document($path)//*[local-name()='variable']">
        <xsl:if test="string-length( @*[local-name()='name'] ) >1">
        <li>
         <xsl:value-of select="position()"/>
        <xsl:value-of select="@*[local-name()='name']"/>
        </li>
        </xsl:if>
      </xsl:for-each>
         <xsl:for-each select="document($path)//*[local-name()='group']">
        <li>
        <xsl:value-of select="position()"/>
        <xsl:value-of select="@*[local-name()='name']"/>
        </li>
      </xsl:for-each>

そしてそれは私に与えるでしょう

1.time
1.Vector

では、この position() 関数を使用して目標を達成するにはどうすればよいでしょうか? または、XSLT でこれを行うための他のより良い方法はありますか? よろしくお願いします。

4

1 に答える 1

1

使用できますposition()が、同じ繰り返し命令内で使用する必要があります。接頭辞を使用して名前空間を宣言し、x次を使用します。

<xsl:for-each select="document($path)//x:netcdf/*
      [self::x:variable or self::x:group]"/>

さらに、私はxsl:number次のように使用します:

<xsl:number value="position()" format="1."/>

local-name()テストを取り除くことができるように、スタイルシートでデフォルトの名前空間を宣言することも検討してください。

于 2011-08-11T07:24:01.903 に答える