0

次のようなXMLを指定します。

<?xml version="1.0" encoding="UTF-8"?>
<Products>
  <Product someId="1EFAD9659EC">
    <Identifiers>
      <Identifier Id="234532423" Name="globalTradeItemNumber (GTIN)" Value="00671657621322" />
      <Identifier Id="99845898" Name="Internal Supplier Part #" Value="DEL 20 10B015000" />
      <Identifier Id="49348598" Name="MFG Model # (Series)" Value="DEL 20 10B015000" />
      <Identifier Id="439854985" Name="MFG Part # (OEM)" Value="DEL 20 10B015000" />
      <Identifier Id="2349832489" Name="UPC" Value="671657621322" />
    </Identifiers>
  </Product>    
  <Product someId="1EFAD9659EC">
    <Identifiers>
      <Identifier Id="234532423" Name="globalTradeItemNumber (GTIN)" Value="51651518" />
      <Identifier Id="99845898" Name="Internal Supplier Part #" Value="TIM 20 10B015000" />
      <Identifier Id="49348598" Name="MFG Model # (Series)" Value="TOM 20 10B015000" />
      <Identifier Id="439854985" Name="MFG Part # (OEM)" Value="TAK 20 10B015000" />
      <Identifier Id="2349832489" Name="UPC" Value="87468387468" />
    </Identifiers>
  </Product>    
      . . .

私は次のようなものになりたい

...
  <Product upc="671657621322"/>
  <Product upc="87468387468"/>
...

しかし、私が得ているのは

...
  <Product upc="true"/>
  <Product upc="true"/>
...

属性の値ではなく、selectに対するブール値の回答を取得し続けます。私がここで間違っているのはどのような愚かなことですか?これは私が試しているXSLTです:

...
    <xsl:template match="/">
        <Output>
            <xsl:apply-templates />
        </Output>
    </xsl:template>

    <xsl:template match="Product">
        <xsl:variable name="productCode" select="./Identifiers/Identifier/@Name='UPC'"/>
        <Product upc="{$productCode}">
        </Product>
    </xsl:template>
...

ありがとう。

4

2 に答える 2

2

間違ったxpath選択を使用しています。使用する:

select="Identifiers/Identifier[@Name='UPC']/@Value"
于 2013-03-26T20:33:41.590 に答える
0

これらの2つのノード値のみに関心がある場合は、それらをテンプレートと一致させます。

<xsl:template match="Product/Identifiers/Identifier[@Name='UPC']">
    <xsl:variable name="productCode" select="@Value"/>
    <Product upc="{$productCode}">
    </Product>
</xsl:template>
于 2013-03-26T20:36:15.720 に答える