2016-04-07 18 views
1

Kaynağım örnek XMLXSL bir öğeye dayalı bir değer doldurmak için nasıl 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> 

aşağıda gibidir. Yani, yukarıdaki durumda, 3 hat shoule oluşturulabilir. Hedefte, Ürün Tanımını Ürün Kimliği değerine göre doldurabilmem gerekir. Şu anda yapamadığı olduğumu kullanarak XSL 1.0

Beklenen hedef XML aşağıda gibi olmalıdır : Ben hedef açıklamasına doldurmak için farklı fonksiyonları kullanarak çalıştı, ama ben de ilk Açıklaması değerini giriyorum

<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> 

tüm satırlar veya hiç değer doldurulmuyor. Bir süre döngü kullanarak gerekli işlevselliği başarabiliyorum ve Jdev 11g'de aktivite atayabiliyorum.

Bunu XSLT'de nasıl yapabilirim? Aşağıdaki stil kullanma

+0

Sorunuzu, şu anda denediğiniz XSLT'yi göstermek için düzenleyebilir misiniz? Teşekkür ederim! –

cevap

0

kolayca mümkündür:

<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> 

Onun çıkışı:

<?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> 

Bu istenen çıktı sürümü görünüyor, çünkü çıktı olarak beklemek iddia tam olarak bu değildi hatalı olmak. Çıktı versiyonunuzda, tüm SerialOrderNbr s değerleri olarak 'xx' değerine sahiptir, ancak kaynak XML'inizde bunlar farklıdır.

+0

Çok teşekkür ederim .... bu bir çekicilik gibi çalışır! Ve SerialOrderNbr yazım hatası için özür dilerim. Bu tür farklı XSL işlevlerini bulabileceğim herhangi bir bağlantınız var mı? Saygılarımızla teşekkür ederiz. Ve yine bir ton teşekkürler. –

+0

@Mohan P: İyi bir başlangıç ​​[w3schools referansıdır] (http://www.w3schools.com/xsl/xsl_w3celementref.asp). Mükemmel değil, ama çok canlı. – zx485

İlgili konular