[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Newbie needs XSL help, 1-to-many xform, multi-valu
At 2010-12-14 18:41 +0000, thehulk@xxxxxxxxxxx wrote:
My problem is, i do not know how to create multiple elements from a single element with several multi-value child elements. By walking the tree as many times as you need. The order of the child nodes has meaning that is managed by the Notes application, so that the set of multi-value data items has the meaning of one two-dimensional array of data. I've assumed you always have exactly as many cities as you have names. If my application puts three people and their cities into one Notes document, Domino gives me XML much like this (simplified of course): Not a problem. In the solution below I use the position of each of the names as my counter and then walk the information pulling out the repeated information at the location of the counter in each loop. I hope this helps. . . . . . . . . Ken T:\ftemp>type hulk.xml <MyRecord> <BranchID> 12345 </BranchID> <RecordDate> November 3, 2009 </RecordDate> <MyNames> <Name> John Doe </Name> <Name> Rachel Roe </Name> <Name> Biff Jones </Name> </MyNames> <MyCities> <City> Kalamazoo </City> <City> Katmandu </City> <City> Timbuktu </City> </MyCities> </MyRecord> T:\ftemp>xslt hulk.xml hulk.xsl <?xml version="1.0" encoding="utf-8"?> <Transactions> <ATransaction> <Branch> 12345 </Branch> <When> November 3, 2009 </When> <Who> John Doe </Who> <Where> Kalamazoo </Where> </ATransaction> <ATransaction> <Branch> 12345 </Branch> <When> November 3, 2009 </When> <Who> Rachel Roe </Who> <Where> Katmandu </Where> </ATransaction> <ATransaction> <Branch> 12345 </Branch> <When> November 3, 2009 </When> <Who> Biff Jones </Who> <Where> Timbuktu </Where> </ATransaction> </Transactions> T:\ftemp>type hulk.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes"/> <xsl:template match="MyRecord"> <Transactions> <xsl:variable name="this" select="."/> <xsl:for-each select="MyNames/Name"> <xsl:variable name="pos" select="position()"/> <xsl:for-each select="$this"> <ATransaction> <Branch><xsl:apply-templates select="BranchID/node()"/></Branch> <When><xsl:apply-templates select="RecordDate/node()"/></When> <Who> <xsl:apply-templates select="MyNames/Name[$pos]/node()"/> </Who> <Where> <xsl:apply-templates select="MyCities/City[$pos]/node()"/> </Where> </ATransaction> </xsl:for-each> </xsl:for-each> </Transactions> </xsl:template> </xsl:stylesheet> T:\ftemp>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|