Hi Kane,
I hope you had time to go look at the thread. I won't repeat the instructions for downloading MSXSL.EXE.
So, as I understand it, your C# program leaves you with a directory of XML files (presumed to have extension
xml), so you need a mechanism to translate the order into the new order. Taking your PHP script, here is an XSLT that will do the identical transformation:
Code:
[small]<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:output indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<OrderDetail>
<xsl:apply-templates select="ShoppingCart/LineItemSKUList/OrderLineItemItem"/>
</OrderDetail>
</xsl:template>
<xsl:template match="OrderLineItemItem">
<LineItemInfo>
<WarehouseID>01</WarehouseID>
<ItemNumber><xsl:value-of select="SKU"/></ItemNumber>
<OrderQty><xsl:value-of select="Quantity"/></OrderQty>
<ActualSellPrice><xsl:value-of select="UnitPrice"/></ActualSellPrice>
<Cost>0.0</Cost>
<ChargeType/>
<DropShip/>
<DueDate/>
<ExtendedWeight>0.0</ExtendedWeight>
<ItemDescription1><xsl:value-of select="Title"/></ItemDescription1>
<ItemDescription2/>
<ItemID>0</ItemID>
<LineItemType/>
<ListPrice/>
<NonStockFlag>false</NonStockFlag>
<SequenceNumber/>
<ShipInstructionType>false</ShipInstructionType>
<UnitOfMeasure>EA</UnitOfMeasure>
</LineItemInfo>
</xsl:template>[/small]
You can apply this transform using MSXSL.EXE:
Code:
MSXSL.EXE [i]amazonorder[/i].xml TranslateShoppingCart.xsl -o [i]MyAPIOrder[/i].xml
Now, one way to run a command, or set of commands, for all the files in a directory is to use the
FOR Windows CMD statement. Here it is in a simple BAT file that you should modify to meet your needs.
Code:
@SETLOCAL
@ECHO OFF
FOR %%I IN (*.xml) DO MSXSL.EXE %%I TranslateShoppingCart.xsl -o OutputDir\%%~nI-new.xml
ENDLOCAL
The FOR ... IN (
filespec) command allows you to process all the files in a directory meeting the
filespec criterion. The variable %%I has the entire filename, and you can use %%~nI to get the file name (without extension), and %%~xI to get the extension (more
here).
If you want to something more complex than a single line (as you describe in your final paragraph), then write a BAT file that takes the filename as a parameter. The batch file will be written to do all the tasks for a single file. Inside the BAT file, that parameter can be referred to as %1, and its file name (without extension) as %~n1, and the extension as %~x1. You would then call the batch file in the manner of
Code:
FOR %%I IN (filespec) DO CMD /C MYBATCH.BAT %%I
Without the CMD /C, the batch file will not be run in a new process, causing premature termination.
Now, regarding substituting in that new order number - this will require a very simple change to the TranslateShoppingCart.xsl and the MSXSL.EXE command line. You say that the C# program "saves each order as the order number." This is convenient, since %~n1 returns just the file name. Let me know where the new order ID is to be injected in the output, and I will show you how.
I finish with my sample input and output for TranslateShoppingCart.xsl, based on your example above.
Code:
[small]<ShoppingCart>
<LineItemSKUList>
<OrderLineItemItem >
<LineItemType>SKU</LineItemType>
<UnitPrice>61.9500</UnitPrice>
<LineItemID>410486</LineItemID>
<AllowNegativeQuantity>false</AllowNegativeQuantity>
<Quantity>1</Quantity>
<ItemSaleSource>AMAZON_US</ItemSaleSource>
<SKU>CSAW6040</SKU>
<Title>JVC Arsenal CS-AW6040 10" Dual 4ohm Subwoofer B001JT97NW</Title>
<BuyerUserID>whatever@marketplace.amazon.com</BuyerUserID>
<BuyerFeedbackRating>0</BuyerFeedbackRating>
<SalesSourceID>19443127456538</SalesSourceID>
<VATRate>0</VATRate>
<TaxCost>0.0000</TaxCost>
<ShippingCost>14.3900</ShippingCost>
<ShippingTaxCost>0.0000</ShippingTaxCost>
<GiftWrapCost>0.0000</GiftWrapCost>
<GiftWrapTaxCost>0.0000</GiftWrapTaxCost>
<GiftMessage />
<GiftWrapLevel />
<RecyclingFee>0.0000</RecyclingFee>
<UnitWeight UnitOfMeasure="LB">13.2</UnitWeight>
<WarehouseLocation />
<UserName />
<DistributionCenterCode>Rodney Building #104</DistributionCenterCode>
<IsFBA>false</IsFBA>
</OrderLineItemItem>
<OrderLineItemItem >
<LineItemType>SKU</LineItemType>
<UnitPrice>31.9500</UnitPrice>
<LineItemID>410487</LineItemID>
<AllowNegativeQuantity>false</AllowNegativeQuantity>
<Quantity>1</Quantity>
<ItemSaleSource>AMAZON_US</ItemSaleSource>
<SKU>CSAW6040</SKU>
<Title>a different speaker</Title>
<BuyerUserID>whatever@marketplace.amazon.com</BuyerUserID>
<BuyerFeedbackRating>0</BuyerFeedbackRating>
<SalesSourceID>19443127456538</SalesSourceID>
<VATRate>0</VATRate>
<TaxCost>0.0000</TaxCost>
<ShippingCost>5.9000</ShippingCost>
<ShippingTaxCost>0.0000</ShippingTaxCost>
<GiftWrapCost>0.0000</GiftWrapCost>
<GiftWrapTaxCost>0.0000</GiftWrapTaxCost>
<GiftMessage />
<GiftWrapLevel />
<RecyclingFee>0.0000</RecyclingFee>
<UnitWeight UnitOfMeasure="LB">13.2</UnitWeight>
<WarehouseLocation />
<UserName />
<DistributionCenterCode>Rodney Building #104</DistributionCenterCode>
<IsFBA>false</IsFBA>
</OrderLineItemItem>
</LineItemSKUList>
</ShoppingCart>
[/small]
Code:
[small]<OrderDetail>
<LineItemInfo>
<WarehouseID>01</WarehouseID>
<ItemNumber>CSAW6040</ItemNumber>
<OrderQty>1</OrderQty>
<ActualSellPrice>61.9500</ActualSellPrice>
<Cost>0.0</Cost>
<ChargeType/>
<DropShip/>
<DueDate/>
<ExtendedWeight>0.0</ExtendedWeight>
<ItemDescription1>JVC Arsenal CS-AW6040 10" Dual 4ohm Subwoofer B001JT97NW</ItemDescription1>
<ItemDescription2/>
<ItemID>0</ItemID>
<LineItemType/>
<ListPrice/>
<NonStockFlag>false</NonStockFlag>
<SequenceNumber/>
<ShipInstructionType>false</ShipInstructionType>
<UnitOfMeasure>EA</UnitOfMeasure>
</LineItemInfo>
<LineItemInfo>
<WarehouseID>01</WarehouseID>
<ItemNumber>CSAW6040</ItemNumber>
<OrderQty>1</OrderQty>
<ActualSellPrice>31.9500</ActualSellPrice>
<Cost>0.0</Cost>
<ChargeType/>
<DropShip/>
<DueDate/>
<ExtendedWeight>0.0</ExtendedWeight>
<ItemDescription1>a different speaker</ItemDescription1>
<ItemDescription2/>
<ItemID>0</ItemID>
<LineItemType/>
<ListPrice/>
<NonStockFlag>false</NonStockFlag>
<SequenceNumber/>
<ShipInstructionType>false</ShipInstructionType>
<UnitOfMeasure>EA</UnitOfMeasure>
</LineItemInfo>
</OrderDetail>[/small]
I anticipate that you might have some questions...
Tom Morrison
Hill Country Software