Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2013, 01:10 PM
Registered User
 
Join Date: Sep 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Build XML document from two XML inputs

I would like to build an xml document. I have a certain format it should be in.
Code:
<?xml version="1.0" encoding="utf-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<?xml-stylesheet type="text/xsl" href="xslt.xsl"?>
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>XYZ</MerchantIdentifier></Header>
<MessageType>Override</MessageType>
<Message>
<MessageID>1</MessageID><OperationType>Update</OperationType>
<Override><SKU>1234</SKU>
<ShippingOverride><ShipOption>Std Cont US Street Addr</ShipOption><Type>Exclusive</Type><ShipAmount currency="USD">0.00</ShipAmount></ShippingOverride>
<ShippingOverride><ShipOption>Std Cont US PO Box</ShipOption><Type>Exclusive</Type><ShipAmount currency="USD">0.00</ShipAmount></ShippingOverride>
</Override>
</Message>
</AmazonEnvelope>
I would like to repeat the </Message> block over and over and have the <SKU> element populated by another XML document I made. It is a simple XML document to house the 'SKU' element.
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<Row>
		<Column1>5235</Column1>
	</Row>
	<Row>
		<Column1>5211</Column1>
	</Row>
	<Row>
		<Column1>5231</Column1>
	</Row>
	<Row>
		<Column1>1365</Column1>
	</Row>...
</Root>
This is my attempt at XSLT...
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:variable name="plUrl" select="string(SKUlist.xml')" />
    <xsl:variable name="plDoc" select="document($plUrl)" />
    <xsl:variable name="packlist" select="$plDoc/Root" />

    <xsl:template match="/">
       
<xsl:for-each select="$packlist[ROW]">
<Message>
<MessageID>1</MessageID><OperationType>Update</OperationType>
<Override><SKU><xsl:value-of select="Column1"/></SKU>
<ShippingOverride><ShipOption>Std Cont US Street Addr</ShipOption><Type>Exclusive</Type><ShipAmount currency="USD">0.00</ShipAmount></ShippingOverride>
<ShippingOverride><ShipOption>Std Cont US PO Box</ShipOption><Type>Exclusive</Type><ShipAmount currency="USD">0.00</ShipAmount></ShippingOverride>
</Override>
</Message>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>
I am creating in txt editor and viewing this in Firefox browser.
It's not working. Any help would be appreciated. Seems a simple process.

Last edited by daplex; October 1st, 2013 at 01:01 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create an XML document using JAXP and XML fragments. WilliamYou XML 2 October 29th, 2012 03:44 PM
Split xml file with result document and javax.xml.transform.Transformer. nisargmca XSLT 3 January 12th, 2010 06:26 AM
Several source dirs in build.xml pranxas Apache Tomcat 1 October 11th, 2006 01:48 PM
XML document error jaffir BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 26th, 2005 12:21 PM
xml document androger XML 2 November 19th, 2003 05:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.