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
pulin thakkarSubject: Generic XSLT..too complex..help please
Author: pulin thakkar
Date: 27 Apr 2007 11:18 AM
Hi All,
I am new to XSLT, just a learner. I downloaded a trial version of Stylus studio Enterprise to see if I can generate XSLT code from source and targe XML. I can see that it does generate, but it hardcodes the elements and nodes which i do not want.
I would appreciate if you guys can help me in creating a XSLT file from my input and output XML.
The input XML is like this
<?xml version="1.0" encoding="UTF-8" ?>
<ns0:MT_UPDATEPERSONACUSTOMERS xmlns:ns0="urn:sd:sales:sapcustomersupdatetopersona">
<CallProc><UPDATE_EndCustomerFromSAP action="EXECUTE">
<SAPID type="CHAR">0000206320</SAPID>
<DateCreated hasQuot="No" type="DATE">2007-04-24</DateCreated>
<FirstName type="CHAR">CAROL J</FirstName>
<LastName type="CHAR">VERITY</LastName>
<AccountGroup type="CHAR">Z001</AccountGroup>
<CustomerStatus type="INTEGER">NULL</CustomerStatus>
<Active type="INTEGER">1</Active>

My output XML should be like this
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_Generic xmlns:ns0="urn:sd:sales:genericcall">
<wrapper action="EXECUTE">
<p1 type = "VARCHAR">mk_INSERT_ConsultantFromSAP_proc</p1>
<p2 type = "VARCHAR">@SAPID = 0000206320</p2>
<p3 type = "VARCHAR">@DateCreated = 2007-04-24</p3>
<p4 type = "VARCHAR">@FirstName = CAROL J</p4>
<p5 type = "VARCHAR">@LastName = VERITY</p5>
<p6 type = "VARCHAR">@AccountGroup = Z001</p6>
<p7 type = "VARCHAR">@CustomerStatus = NULL</p7>
<p8 type = "VARCHAR">@Active = 1</p8>

I think if <p1> tag is hardcoded then its fine, but the value "mk_insert.." should be picked up from table tag in source XML.
Now the difficult part is that p2, p3, pn are dynamic, they should be generated based on number of child nodes in source XML. I need to use something like contact('p',$counter) which will create <p1>, <p2>,,<pn> tags and also i need corresponding </p1></p2></pn> closing tags.
Then i want (key = value) pairs extracted from source XML to be plugged in these p1, pn tags. This process has to be generic as source XML can have varying number of tags, means in the example i have give there are 8 child nodes, but it can go to 12 or 18 or 30. Also the namespace can keep on changing, but i can give you one thing to start with, the action attribute and table element is always there irrespective of any XML input given. I do not know how to use those descendent, sibling ,etc. tags, but i think this complex scenario is possible in XSLT.
Though i am a very good programmer in SAP, XSLT has beaten me. Since last 3 days I am trying to learn and implent this, but struggling. I would greatly appreciate your inputs. Thanks in advance

Alberto MassariSubject: Generic XSLT..too complex..help please
Author: Alberto Massari
Date: 30 Apr 2007 10:21 AM
Hi Pulin,
you need to use xsl:element and the 'following-sibling' axis

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"

<xsl:template match="/">
<ns0:MT_Generic xmlns:ns0="urn:sd:sales:genericcall">
<xsl:for-each select="/nsxml:MT_UPDATEPERSONACUSTOMERS/CallProc/UPDATE_EndCustomerFromSAP">
<wrapper action="{@action}">
<p1 type = "VARCHAR"><xsl:value-of select="table"/></p1>
<xsl:for-each select="table/following-sibling::*">
<xsl:element name="p{position()+1}">@<xsl:value-of select="name()"/> = <xsl:value-of select="text()"/></xsl:element>


Hope this helps,

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!  

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.