[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

Subject: Re: 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
Re:  Newbie needs XSL help
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
 <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>


-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.