2016-04-07 8 views
1

私のソースサンプルXMLはXSLの要素に基づいて値を移入する方法1.0

<QuoteData> 
    <Components> 
     <Component ServiceOfferingId="XX" StartDate="07/03/2016" EndDate="12/31/9999" SerialOrderNbr="xx" StopReasonCode="" IsBundle="N"> 
      <ServiceItem ItemType="xx" Type="2072" ModelFeature="24E" ProductId="2072 24E" SerialOrderNbr="xx" Quantity="1" StartDate="07/03/2016" EndDate="12/31/9999" CustomerId="xx" ServiceLevelId="xx"/> 
     </Component> 
     <Component ServiceOfferingId="yy" StartDate="07/03/2016" EndDate="12/31/9999" SerialOrderNbr="yy" StopReasonCode="" IsBundle="N"> 
      <ServiceItem ItemType="yy" Type="2072" ModelFeature="24C" ProductId="2072 24C" SerialOrderNbr="yy" Quantity="1" StartDate="07/03/2016" EndDate="12/31/9999" CustomerId="yy" ServiceLevelId="yy"/> 
      <ServiceItem ItemType="zz" Type="2072" ModelFeature="24E" ProductId="2072 24E" SerialOrderNbr="zz" Quantity="1" StartDate="07/03/2016" EndDate="12/31/9999" CustomerId="zz" ServiceLevelId="zz"/> 
     </Component> 
    </Components> 
    <Descriptions> 
     <ProductDescription Id="2072 24E" Description="Customer EXPANSION"/> 
     <ProductDescription Id="2072 24C" Description="Customer CONTROL"/> 
    </Descriptions> 
</QuoteData> 

以下の通りです。したがって、上記の場合、3行のshouleが作成されます。 ターゲットでは、商品IDの値に基づいて商品説明を入力できるはずです。

<Payload> 
    <Header></Header> 
    <Line> 
     <SerialOrderNbr>xx</SerialOrderNbr> 
     <ModelFeature>24E</ModelFeature> 
     <ProductId>2072 24E</ProductId> 
     <ProductDescription>Customer EXPANSION</ProductDescription> 
    </Line> 
    <Line> 
     <SerialOrderNbr>xx</SerialOrderNbr> 
     <ModelFeature>24C</ModelFeature> 
     <ProductId>2072 24C</ProductId> 
     <ProductDescription>Customer CONTROL</ProductDescription> 
    </Line> 
    <Line> 
     <SerialOrderNbr>xx</SerialOrderNbr> 
     <ModelFeature>24E</ModelFeature> 
     <ProductId>2072 24E</ProductId> 
     <ProductDescription>Customer EXPANSION</ProductDescription> 
    </Line> 
</Payload> 

私は、ターゲットの記述を移入するためにさまざまな機能を使ってみましたが、私はどちらかの最初の説明値を取得しています:現在、私は、XSL 1.0

を使用して

予想されるターゲットXMLは以下のようにする必要があることを行うことができませんすべての行または値がまったく入力されていません。私はwhileループを使用して必要な機能を実現し、Jdev 11gでアクティビティを割り当てることができます。

これをXSLTでどうやって行うことができますか?

+0

質問を編集して、現在試したXSLTを表示できますか?ありがとうございました! –

答えて

0

次のスタイルシートを使用することが容易に可能である:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" /> 
    <xsl:template match="/QuoteData"> 
    <Payload> 
     <xsl:for-each select="//ServiceItem"> 
     <line> 
      <SerialOrderNbr><xsl:value-of select="@SerialOrderNbr" /></SerialOrderNbr> 
      <ModelFeature><xsl:value-of select="@ModelFeature" /></ModelFeature> 
      <ProductId><xsl:value-of select="@ProductId" /></ProductId> 
      <ProductDescription><xsl:value-of select="//ProductDescription[@Id = current()/@ProductId]/@Description" /></ProductDescription> 
     </line> 
     </xsl:for-each> 
    </Payload> 
    </xsl:template>  
</xsl:stylesheet> 

その出力は次のようになります。

<?xml version="1.0"?> 
<Payload> 
    <line> 
     <SerialOrderNbr>xx</SerialOrderNbr> 
     <ModelFeature>24E</ModelFeature> 
     <ProductId>2072 24E</ProductId> 
     <ProductDescription>Customer EXPANSION</ProductDescription> 
    </line> 
    <line> 
     <SerialOrderNbr>yy</SerialOrderNbr> 
     <ModelFeature>24C</ModelFeature> 
     <ProductId>2072 24C</ProductId> 
     <ProductDescription>Customer CONTROL</ProductDescription> 
    </line> 
    <line> 
     <SerialOrderNbr>zz</SerialOrderNbr> 
     <ModelFeature>24E</ModelFeature> 
     <ProductId>2072 24E</ProductId> 
     <ProductDescription>Customer EXPANSION</ProductDescription> 
    </line> 
</Payload> 

所望の出力のバージョンがそうなのでこれは、あなたが出力として期待する主張を正確にものではありません間違っているあなたの出力バージョンでは、すべてSerialOrderNbrは値として 'xx'を持っていますが、ソースXMLではそれらは異なります。

+0

すっごくありがとうございました....魅力的ですね!!そして、SerialOrderNbrのタイプミスで申し訳ありません。私はこれらの種類の異なるXSL関数を見つけることができるリンクを持っていますか?ご回答いただき誠にありがとうございます。そしてもう一度お返事してください。 –

+0

@Mohan P:良いスタートは[w3schoolsのリファレンス](http://www.w3schools.com/xsl/xsl_w3celementref.asp)です。完璧ではありませんが、非常に鮮やかです。 – zx485

関連する問題