0

要素から値を取得しようとしています。問題は、要素が複数回表示される可能性があり、比較する必要がある別の要素内にネストされていないことです。

これが私のXMLの一部です:

<sim_pur_pric>
  <spp_code>001</spp_code> 
  <spp_price>213.0136</spp_price> 
  <spp_unit>ea</spp_unit> 
  <spp_curr>USD</spp_curr> 
  <spp_cost_comp>001</spp_cost_comp> 
  </sim_pur_pric>
<sim_pur_pric>
  <spp_code>005</spp_code> 
  <spp_price>212.498553</spp_price> 
  <spp_unit>ea</spp_unit> 
  <spp_curr>USD</spp_curr> 
  <spp_cost_comp>001</spp_cost_comp> 
  </sim_pur_pric>
  <storage_conditions /> 
  <cust_po />

取得する必要があるのは spp_price の値ですが、spp_code が 001 の場合のみですが、ご覧のとおり、要素 sim_pur_pric は異なる spp_code に対して 2 回表示されます。

これは私のxsl(その一部)にあるものです:

<xsl:template match="sim_pur_pric">
  <xsl:choose>
    <xsl:when test="spp_code"='001'">
      <xsl:choose>
        <xsl:when test="string-length(spp_price) != 0">
          <xsl:value-of select='spp_price'/><xsl:text>|</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>0|</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>0|</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

しかし、それは機能しません... :( 実験した人の中に、私が望む値を得る方法を知っている人はいますか?私はあなたの時間と助けに感謝します

最後に、xsltproc を使用して Unix で解析しているため、XSL バージョン 1.0 である必要があります。

4

1 に答える 1