2016-04-07 7 views
1

Meine Quelle XML-Beispiel ist als untenWie Wert aufzufüllen basierend auf einem Element in 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> 

wie pro Anforderung sollte jeder ServiceItem in eine Linie umgewandelt werden. Also, im obigen Fall, 3 Zeilen Shoule erstellt werden. Im Ziel sollte ich in der Lage sein, die Produktbeschreibung basierend auf dem Produkt-ID-Wert aufzufüllen. Ich bin derzeit nicht in der Lage zu tun, dass die Verwendung von XSL 1.0

Erwartete XML-Ziel wie unten sein sollte:

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

ich verschiedene Funktionen versucht, mit der Zielbeschreibung zu füllen, aber ich bin entweder die erste Beschreibung Wert immer in Alle Zeilen oder kein Wert wird ausgefüllt. Ich bin in der Lage, die erforderliche Funktionalität mit einer while-Schleife zu erreichen und Aktivität in Jdev 11g zuweisen.

Wie kann ich dies in XSLT tun?

+0

Können Sie Ihre Frage bearbeiten, um die XSLT anzuzeigen, die Sie gerade ausprobiert haben? Vielen Dank! –

Antwort

0

das folgende Stylesheet zu verwenden ist ohne weiteres möglich:

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

Sein Ausgang ist:

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

Dies ist nicht genau das, was Sie als Ausgang zu erwarten, dadurch gekennzeichnet, dass Ihre Version der gewünschten Ausgabe scheint falsch sein. In Ihrer Ausgabeversion haben alle SerialOrderNbr s 'xx' als Wert, aber in Ihrem Quell-XML sind sie unterschiedlich.

+0

Vielen Dank .... es funktioniert wie ein Charme !!. Und sorry für den Tippfehler in SerialOrderNbr. Haben Sie einen Link, wo ich diese Art von verschiedenen XSL-Funktionen finden kann. Vielen Dank für Ihre Antwort. Und nochmals vielen Dank. –

+0

@Mohan P: Ein guter Anfang ist [die Referenz bei w3schools] (http://www.w3schools.com/xsl/xsl_w3celementref.asp). Es ist nicht perfekt, aber sehr lebendig. – zx485