2016-06-23 12 views
0

Ich importiere eine XML-Datei in Access und benutze eine xslt-Datei, um die Datei so umzuwandeln, dass sie die orderNumber für jeden Abschnitt enthält. Nicht sicher über den richtigen Begriff. In dem Code unten bekomme ich das Feld und Bestellnummer für die Artikel hinzugefügt, und nur das Feld für die anderen Abschnitte, shippingAddress, Zahlung, etc ..Transformiere xslt nicht alle Elemente umwandeln

Ich verstehe nicht ganz, wo ich Änderungen vornehmen muss Die Daten für Bestellnummer wurden den Feldern hinzugefügt.

Jede Hilfe würde sehr geschätzt werden.

Greg

Das ist, was mir gegeben wird, mit zu arbeiten.

<?xml version="1.0" encoding="UTF-8"?> 
-<orders xmlns:php="http://php.net/xsl"> 
-<order> 
     <orderNumber>100000379</orderNumber> 
-<billingAddress> 
      <company>Acme</company> 
      <name>John Doe</name> 
      <address1>59 Any St</address1> 
      <address2/> 
      <city>New York</city> 
      <state>NY</state> 
      <zip>10013-4020</zip> 
      <country>US</country> 
      <phone>212-555-1212</phone> 
     </billingAddress> 
-<shippingAddress> 
      <company>Acme</company> 
      <name>John Doe</name> 
      <address1>59 Any St</address1> 
      <address2/> 
      <city>New York</city> 
      <state>NY</state> 
      <zip>10013-4020</zip> 
      <country>US</country> 
      <phone>212-555-1212</phone> 
     </shippingAddress> 
     <createdOn>2016-06-22 14:38:06</createdOn> 
     <shipMethod>ups_GND</shipMethod> 
     <shipDescription>United Parcel Service - Ground</shipDescription> 
-<payment> 
      <tax>0</tax> 
      <shipmentCost>26.76</shipmentCost> 
      <subtotalExclTax>1616</subtotalExclTax> 
      <subtotalInclTax>1616</subtotalInclTax> 
      <discount>0</discount> 
      <grandTotal>1642.76</grandTotal> 
      <paymentMethod>purchaseorder</paymentMethod> 
     </payment> 
-<items> 
-<item> 
       <itemId>645</itemId> 
       <productId>171</productId> 
       <sku>12749</sku> 
       <qty>1</qty> 
       <price>858</price> 
       <tax>0</tax> 
       <itemTotal>858</itemTotal> 
      </item> 
-<item> 
       <itemId>646</itemId> 
       <productId>178</productId> 
       <sku>127478</sku> 
       <qty>1</qty> 
       <price>758</price> 
       <tax>0</tax> 
       <itemTotal>758</itemTotal> 
      </item> 
     </items> 
    </order> 
</orders> 

Dies ist der xslt-Code. Ich habe das als Beispiel gefunden, aber ich kann es nicht funktionieren lassen.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="/"> 
    <dataroot> 
     <xsl:apply-templates select="@*|node()"/> 

    </dataroot> 
</xsl:template> 

<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 

    </xsl:copy> 
</xsl:template> 

<xsl:template match="billingAddress"> 
    <billingAddress> 
     <orderNumber><xsl:value-of select="../../orderNumber"/></orderNumber> 
     <xsl:apply-templates select="node()"/> 
    </billingAddress> 
</xsl:template> 

<xsl:template match="shippingAddress"> 
    <shippingAddress> 
     <orderNumber><xsl:value-of select="../../orderNumber"/></orderNumber> 
     <xsl:apply-templates select="node()"/> 
    </shippingAddress> 
</xsl:template> 

<xsl:template match="payment"> 
    <payment> 
     <orderNumber><xsl:value-of select="../../orderNumber"/></orderNumber> 
     <xsl:apply-templates select="node()"/> 
    </payment> 
</xsl:template> 

<xsl:template match="items"> 
    <xsl:apply-templates select="@*|node()"/> 
</xsl:template> 

<xsl:template match="item"> 
    <item> 
     <orderNumber><xsl:value-of select="../../orderNumber"/></orderNumber> 
     <xsl:apply-templates select="@*|node()"/> 
    </item> 
</xsl:template> 

+0

Parfait, Thank you very much. Lerne jeden Tag etwas Neues. – Greg

Antwort

0

<orderNumber> Das Element ist ein Geschwister des <billingAddress>, <shippingAddress>, <payment> aber ein Niveau oberhalb <items>. Ihre Kontextebenen-Direktive ../../ funktioniert also nur für <item> Knoten.

einfach ersetzen:

<xsl:value-of select="../../orderNumber"/> 

mit einem gemeinsamen Ausdruck als <order> der Vorfahre aller erforderlichen Knoten ist:

<xsl:value-of select="ancestor::order/orderNumber"/>