This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Copying Node Multiple Time
- To: xsl-list at lists dot mulberrytech dot com
- Subject: [xsl] Copying Node Multiple Time
- From: amarjit dot s dot bhullar at accenture dot com
- Date: Wed, 4 Apr 2001 16:58:10 -0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
I have the following XML document.
<Cart>
<ItemIn quantity="2" lineNumber="1">
<ItemID>
<SupplierPartID>1030</SupplierPartID>
<SupplierPartAuxiliaryID>289,472967,3,,,,,</SupplierPartAuxiliaryID>
</ItemID>
</ItemIn>
</Cart>
The output would look as follows
<NewCart>
<ItemIn quantity="1" lineNumber="1">
<ItemID>
<SupplierPartID>1030</SupplierPartID>
<SupplierPartAuxiliaryID>289,472967,3,,,,,</SupplierPartAuxiliaryID>
</ItemID>
</ItemIn>
<ItemIn quantity="1" lineNumber="2">
<ItemID>
<SupplierPartID>1030</SupplierPartID>
<SupplierPartAuxiliaryID>289,472967,3,,,,,</SupplierPartAuxiliaryID>
</ItemID>
</ItemIn>
</NewCart>
I would like to use the quantity attribute to create multiple copies of the
ItemIn node and set the quantity attribute to 1 and increment the line
number.
I have started with the following XSL code and would like to know how to
create a loop to do multiple copies.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl
="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<NewCart>
<xsl:for-each select="//ItemID">
<xsl:sort select
="substring-before(SupplierPartAuxiliaryID,',')" data-type="number"/>
<xsl:sort select="SupplierPartID" data-type="number"/>
<xsl:copy-of select="parent::node()"/>
</xsl:for-each>
</NewCart>
</xsl:template>
</xsl:stylesheet>
Any help would be appreciated.
Thanks
Amarjit
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list