Re: [xsl] Newbie needs XSL help, 1-to-many xform, multi-value data items

Subject: Re: [xsl] Newbie needs XSL help, 1-to-many xform, multi-value data items
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Dec 2010 14:01:31 -0500
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):
I need to turn that one "MyRecord" element into multiple "ATransaction" elements (three of them, in this case). Each of them has certain data from "MyRecord", along with only one value from each of the multi-child elements "MyNames" and "MyCities".

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
   <BranchID> 12345 </BranchID>
   <RecordDate> November 3, 2009 </RecordDate>
      <Name> John Doe </Name>
      <Name> Rachel Roe </Name>
      <Name> Biff Jones </Name>
      <City> Kalamazoo </City>
      <City> Katmandu </City>
      <City> Timbuktu </City>
T:\ftemp>xslt hulk.xml hulk.xsl
<?xml version="1.0" encoding="utf-8"?>
      <Branch> 12345 </Branch>
      <When> November 3, 2009 </When>
      <Who> John Doe </Who>
      <Where> Kalamazoo </Where>
      <Branch> 12345 </Branch>
      <When> November 3, 2009 </When>
      <Who> Rachel Roe </Who>
      <Where> Katmandu </Where>
      <Branch> 12345 </Branch>
      <When> November 3, 2009 </When>
      <Who> Biff Jones </Who>
      <Where> Timbuktu </Where>
T:\ftemp>type hulk.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="";

<xsl:output indent="yes"/>

<xsl:template match="MyRecord">
    <xsl:variable name="this" select="."/>
    <xsl:for-each select="MyNames/Name">
      <xsl:variable name="pos" select="position()"/>
      <xsl:for-each select="$this">
          <Branch><xsl:apply-templates select="BranchID/node()"/></Branch>
          <When><xsl:apply-templates select="RecordDate/node()"/></When>
            <xsl:apply-templates select="MyNames/Name[$pos]/node()"/>
            <xsl:apply-templates select="MyCities/City[$pos]/node()"/>


-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers:

Current Thread