[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML/XSL help

  • From: "G. Ken Holman" <gkholman@C...>
  • To: "'xml-dev@l...'" <xml-dev@l...>
  • Date: Tue, 01 Aug 2000 20:27:57 -0400

xml xsl help
At 00/08/01 19:54 -0400, Ravi Ramamirtham wrote:
>I am trying to generate an XML fragment from multivalued LDAP attributes. My
>data(in DSML form) looks like:
>         <attr name="xyz">
>             <value>1</value>
>             <value>2</value>
>             </attr>
>             <attr name="abc">
>             <value>10</value>
>             <value>20</value>
>         </attr>
>The XML I want should look something like:
>         <data>
>             <xyz>1</xyz>
>             <abc>10</abc>
>         </data>
>         <data>
>             <xyz>2</xyz>
>             <abc>20</abc>
>         </data>
>I am having difficulties writing XSL to transform the DSML to XML.

XSL, XSLT and XPath questions would be better posted to the following list:


There are a number of subscribers who would enthusiastically respond to 
such questions.

>help/pointers/suggestions would be much appreciated.

I think the most appropriate solution uses a recursively-called template, 
since I'm guessing there may be mis-matched counts of <value> children of 
<attr> elements so looping as long as there are *any* children at a 
particular index value would produce the result you need.

I am unfamiliar with the LDAP requirements you are trying to fulfill, so 
I'm not sure about the integrity of matched numbers of value children.

I've attached the shape of a solution below ... it keeps looping through 
the data set as long as there are values to be output.  It will work 
regardless of whether there are matched counts of children or not.

I hope this helps.

................. Ken

T:\ftemp>type ravi.xml
<?xml version="1.0"?>
         <attr name="xyz">

             <attr name="abc">
T:\ftemp>type ravi.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:output indent="yes"/>

<xsl:template match="/info"> <!--package results in doc. elem.-->
     <xsl:call-template name="loop"/>

<xsl:template name="loop">    <!--recursively-called construct-->
   <xsl:param name="index" select="1"/>
        <!--only put out correlated values if there is an entry-->
   <xsl:if test="attr/value[$index]">   <!--at least one exists-->
     <data>           <!-- put out each value for a given entry-->
       <xsl:for-each select="attr[value[$index]]">
         <xsl:element name="{@name}">           <!--named value-->
           <xsl:value-of select="value[$index]"/>
     <xsl:call-template name="loop">     <!--check for any more-->
       <xsl:with-param name="index" select="$index + 1"/>


T:\ftemp>xt ravi.xml ravi.xsl ravi.out

T:\ftemp>type ravi.out
<?xml version="1.0" encoding="utf-8"?>

G. Ken Holman                    mailto:gkholman@C...
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Web site: XSL/XML/DSSSL/SGML services, training, libraries, products.
Book: Practical Transformation Using XSLT and XPath ISBN1-894049-05-5
Next instructor-led training:    2000-09-19/20,2000-10-03,2000-10-04,
-              2000-10-05,2000-10-19,2000-11-12,2000-11-13,2001-01-27


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.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.

Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.