XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Gagan RastogiSubject: XSLT to XML: Urgent Help Needed.
Author: Gagan Rastogi
Date: 18 Aug 2006 11:05 AM
Hi,

I have an XML which is something like this:

Source XML:
<MAIN_REPORT>
<FIELD NAME="FirstName1">SUSAAI</FIELD>
<FIELD NAME="FirstName2">Carla</FIELD>
<FIELD NAME="FirstName3">michael</FIELD>
<FIELD NAME="MiddleName1">A</FIELD>
<FIELD NAME="MiddleName2">B</FIELD>
<FIELD NAME="MiddleName3">C</FIELD>
<FIELD NAME="LastName1">JONES</FIELD>
<FIELD NAME="LasName2">Smith</FIELD>
<FIELD NAME="LastName3">Candy</FIELD>
<FIELD NAME="Suffix1">MRS</FIELD>
<FIELD NAME="Suffix2">Mr</FIELD>
<FIELD NAME="Suffix3">MRS</FIELD>
</MAIN_REPORT>

I would like to transform this XML into this:

<MAIN_REPORT>
<PERSON_NAME>
<FirstName1>SUSAAI</FirstName1>
<MiddleName1>A</MiddleName1>
<LastName1>JONES</LastName1>
<Suffix1>MRS</Suffix1>
<PERSON_NAME>
<PERSON_NAME>
<FirstName2>Carla</FirstName2>
<MiddleName2>B</MiddleName2>
<LastName2>Smith</LastName2>
<Suffix2>MR</Suffix2>
<PERSON_NAME>
<PERSON_NAME>
<FirstName3>michael</FirstName3>
<MiddleName3>C</MiddleName3>
<LastName3>Candy</LastName3>
<Suffix3>MRS</Suffix3>
<PERSON_NAME>
</MAIN_REPORT>

I would like to use XSLT for transformation.

I would very much appreciate any help in this matter. Please its very urgent.

Thanks.

Gagan

Postnext
Ivan PedruzziSubject: XSLT to XML: Urgent Help Needed.
Author: Ivan Pedruzzi
Date: 18 Aug 2006 12:03 PM

Gagan,

This forum is for Stylus Studio users only and we can't find your email address in our records.

Which Stylus Studio version are you running?



Ivan Pedruzzi
Stylus Studio Team
http://www.stylusstudio.com/xml_download.html

Postnext
Gagan RastogiSubject: XSLT to XML: Urgent Help Needed.
Author: Gagan Rastogi
Date: 18 Aug 2006 12:14 PM
Hi,

i am using Stylus studio enterprise adition 2.0. I have subscribed to trial. I am registered under gagan.rastogi@unisys.com

Thanks.

Postnext
Gagan RastogiSubject: XSLT to XML: Urgent Help Needed.
Author: Gagan Rastogi
Date: 18 Aug 2006 12:24 PM
Is there any way somebody could help me with this. Thanks.

Postnext
Minollo I.Subject: XSLT to XML: Urgent Help Needed.
Author: Minollo I.
Date: 18 Aug 2006 01:00 PM
You will need to be a bit more patient; we usually answer questions unrelated to the Stylus Studio usage (like "how do I do this with XSLT") whenever we have a chance, but we won't guarantee that happens in a few minutes/hours period. You may want to investigate asking your XSLT questions on the XSLT list at http://www.mulberrytech.com/xsl/xsl-list/index.html.

In the meanwhile, it would be good to have some more information:
- Are the values in FIELD/@NAME "stable"? Is the first part always that one ("FirstName", "MiddleName", ...), followed by a numeric suffix?
- In the generated XML, is there always a 1 to 1 mapping between the FIELD/@NAME value and the generated elements?

Thanks.

Postnext
Gagan RastogiSubject: XSLT to XML: Urgent Help Needed.
Author: Gagan Rastogi
Date: 18 Aug 2006 01:21 PM
yes the names are fixed and only the suffix change in sequential order.
also there is a one to one mapping of the field/attribute combination.

Thanks.

Posttop
Minollo I.Subject: XSLT to XML: Urgent Help Needed.
Author: Minollo I.
Date: 18 Aug 2006 01:49 PM
If it's all that "static", then something like this may help:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<MAIN_REPORT>
<xsl:apply-templates select="//FIELD[substring(@NAME, 1, 9) = 'FirstName']"/>
</MAIN_REPORT>
</xsl:template>

<xsl:template match="FIELD">
<PERSON_NAME>
<xsl:element name="{@NAME}">
<xsl:value-of select="."/>
</xsl:element>
<xsl:variable name="index" select="number(substring(@NAME, 10, 1))"/>
<xsl:call-template name="addField">
<xsl:with-param name="name" select="'MiddleName'"/>
<xsl:with-param name="index" select="$index"/>
</xsl:call-template>
<xsl:call-template name="addField">
<xsl:with-param name="name" select="'LastName'"/>
<xsl:with-param name="index" select="$index"/>
</xsl:call-template>
<xsl:call-template name="addField">
<xsl:with-param name="name" select="'Suffix'"/>
<xsl:with-param name="index" select="$index"/>
</xsl:call-template>
</PERSON_NAME>
</xsl:template>


<xsl:template name="addField">
<xsl:param name="name"/>
<xsl:param name="index"/>
<xsl:if test="//FIELD[@NAME = concat($name, $index)]">
<xsl:element name="{concat($name, $index)}">
<xsl:value-of select="//FIELD[@NAME = concat($name, $index)]"/>
</xsl:element>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.