473,472 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSLT transformaton (result XML shld be in same sequence always...

Hi,

1. My source XML will almost look like attached "Source.XML"

2. I have to transform that into Destination XML almost look like
attached"Dest.xml"

Here, my destination XML should be always in the same sequence of
elements as it is in sample shown whatever way the Source XML
comes...OR XSL transforms it...

Please advice how to I achieve it...One rude way is write for each
Column Details one For loop...which is worst, I know in all ways.

Your early advice will help me a lot. (let me know if any further
clarification required on my prob).

Ravi Velamuri.

Source.xml:

<?xml version="1.0"?>
<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:///d:sample.xsd">
<Table_Info>
<Table_Name>TBLGS_COUNTRY</Table_Name>
<Operation_Type>I</Operation_Type>
<Prev_Seq>190952</Prev_Seq>
<Curr_Seq/>
</Table_Info>
<Table_Data>
<Col_Details>
<Col_Name>GS_CURR</Col_Name>
<Col_Value>JPY</Col_Value>
</Col_Details>
<Col_Details>
<Col_Name>GS_CTRY_ABBR</Col_Name>
<Col_Value/>
</Col_Details>
<Col_Details>
<Col_Name>GS_CTRY</Col_Name>
<Col_Value>CTRY attribute</Col_Value>
</Col_Details>
<Col_Details>
<Col_Name>GS_CTRY_DES</Col_Name>
<Col_Value>JAPAN</Col_Value>
</Col_Details>
<Col_Details>
<Col_Name>BLB_ISO_CTRY</Col_Name>
<Col_Value>JP</Col_Value>
</Col_Details>
<Col_Details>
<Col_Name>BLB_ISO_CTRY_DES</Col_Name>
<Col_Value/>
</Col_Details>
<Col_Details>
<Col_Name>BLB_CDR_CTRY</Col_Name>
<Col_Value/>
</Col_Details>
</Table_Data>
<Error_Info>
<Error_Msg1/>
<Error_Msg2/>
</Error_Info>
</TEST>

XSL transform logic:

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:abc="http://www.abc.com/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template name="country">
<xsl:for-each select="TEST/Table_Data/Col_Details">
<xsl:if test="Col_Name = 'BLB_ISO_CTRY'">
<test:code>
<xsl:value-of select="Col_Value"/>
</test:code>
</xsl:if>
<xsl:if test="Col_Name= 'GS_CTRY_DES'">
<test:name>
<xsl:value-of select="Col_Value"/>
</test:name>
</xsl:if>

<xsl:if test="Col_Name = 'GS_REGION_CODE'">
<test:timezone>
<xsl:value-of select="Col_Value"/>
</test:timezone>
</xsl:if>
<xsl:if test="Col_Name = 'GS_CTRY'">
<attribute>
<test:name>
GS_CTRY
</test:name>
<test:value>
<xsl:value-of select="Col_Value"/>
</test:value>
</attribute>
</xsl:if>
<xsl:if test="Col_Name = 'GS_CURR'">
<attribute>
<test:name>
GS_CURR
</test:name>
<test:value>
<xsl:value-of select="Col_Value"/>
</test:value>
</attribute>
</xsl:if>
</xsl:for-each>
<test:enabled> true </test:enabled>
</xsl:template>
</xsl:stylesheet>

Dest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<test:testDocument
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:abc="http:/
/www.abc.com/xml">
<test:testObject test:type="TBLGS_COUNTRY" action="I">
<test:Attribute>
<test:name>GS_CTRY</test:name>
<test:value>949</test:value>
</test:Attribute>
<test:Attribute>
<test:name>GS_CURR</test:name>
<test:value/>
</test:Attribute>
<test:name/>
<test:code/>
<test:timezone/>
<test:enabled>true</test:enabled>
<test:activeFrom>1970-01-01+00:00</test:activeFrom>
<test:activeTo>2100-01-01+00:00</test:activeTo>
<test:holiday/>
</test:testObject>
</test:testDocument>

Feb 25 '06 #1
1 1058
Please tell me, do you get to design the input language? If so, there
might be better things to do.

However, there are nicer ways to represent what you are doing now.

One is to use xsl:choose instead of a list of xsl:if elements. This
doesn't actually give you anything other than it looks nicer.

<xsl:choose>
<xsl:when test="Col_Name = 'BLB_ISO_CTRY'">
...
</xsl:when>
...
</xsl:choose>

Another, more modular approach is to use an apply templates. This lets
you import templates from other xsl files.

<xsl:apply-templates select="TEST/Table_Data/Col_Details"
mode="col_details"/>

and then have templates of the form:

<xsl:template match="Col_Name = 'BLB_ISO_CTRY'" mode="col_details">
...
</xsl:template>

Feb 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Mark Constant | last post by:
I posted this on topxml.com and nobody has responded so I was hoping somebody could help me here. I am following some tutorials in VS.NET. I created a XSD schema file and then from there created an...
4
by: cyclops | last post by:
I'm trying to do XML + XSLT -> Another XML. The source XML contains multiple namespaces and XSLT will handle all possible tags under each name space. ----source---- <document xmlns="..."...
2
by: Jon Martin Solaas | last post by:
Hi, I have a general document somewhat like this: -------------------------------------- <root> <level1> <level2> <interestingstuff number="2"/> <interestingstuff number="3"/>...
3
by: David Elliott | last post by:
I wrote an application to scrape a database and create an XSD file which will be annotated by a map file in order to create a Typed DataSet. I was wondering if I could do the annotation using...
0
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections....
2
by: killy971 | last post by:
I have been testing different libraries to process XSL transformations on large XML files. The fact is that I read a document from Intel, stating their library (XSLT accelerator) was more twice...
2
by: RolfK | last post by:
Dear ALL, I need some help on xsl:sequence. I'm using the Altova XSLT processor, but I'm quite confident it is not an processor issue. It's probably my bad knowledge of xslt 2.0. I have probably...
3
by: RolfK | last post by:
Dear ALL, I have to convert a string of "10101010111"to a decimal number. What is the standard solution in XSLT2.0 ? Thanks a lot RolfK
8
by: manugm1987 | last post by:
<?xml-stylesheet type="text/xsl" href="ch1.xsl"?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <style type="text/css"> span.cls_002{...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.