Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 16th, 2012, 10:10 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Unhappy Replacing values in different elements in target xml file

Hi,

I have source XML file, from that I need to put the same values in those elements in different elements in the targed XML file. Need to do this using XSL.

Source XML

Code:
<SearchRequest xmlns = "http://www.nyl_ltc.com/ltc_common">
    <UserLoginName>SHANE</UserLoginName>
    <TransactionGUID>Test ID</TransactionGUID>
    <MaxRecords>20</MaxRecords>
    <CriteriaExpression xmlns = "http://www.ttc.com/shared_transaction">
        <Criteria>
            <PropertyName>LastName</PropertyName>
            <PropertyValue>SCOTT</PropertyValue>
            <Operation>EQUALS</Operation>
        </Criteria>
    </CriteriaExpression>
</SearchRequest>
Target XML

Code:
<TTC xmlns="http://ttc/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2.18.02">
    <UserAuthRequest>
        <UserLoginName>SHANE</UserLoginName>
    </UserAuthRequest>
    <TTCRequest>
        <TransRefGUID>Test ID</TransRefGUID>
        <TransType tc="301"/>
        <TransExeDate>2012-04-26</TransExeDate>
        <TransExeTime>10:28:15</TransExeTime>
        <InquiryLevel tc="3">3</InquiryLevel>
        <MaxRecords>20</MaxRecords>
        <CriteriaExpression>
            <Criteria>
                <ObjectType tc="252">OLI_OLIFEEXTENSION</ObjectType>
                <PropertyName>ProducerIdentifier</PropertyName>
                <PropertyValue>939168</PropertyValue>
                <Operation tc="1"/>
            </Criteria>
        </CriteriaExpression>
    </TTCRequest>
</TTC>
Above you can see my source and target XML are different, How can transform above source XML file using XSL to required target XML.
Reply With Quote
  #2 (permalink)  
Old May 16th, 2012, 10:17 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Unfortunately your source XML and target XML are so different from each other that's it's hard to see what the relationship is. You need to explain something about the rules for getting the target from the source.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old May 16th, 2012, 10:21 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
Unfortunately your source XML and target XML are so different from each other that's it's hard to see what the relationship is. You need to explain something about the rules for getting the target from the source.
Source and Target XML are in different layers of the program, And those layers accepting that format only. Some third party systems anticipates that target XML in that format. So I cannot change it.
Reply With Quote
  #4 (permalink)  
Old May 16th, 2012, 10:31 AM
Registered User
Points: 23, Level: 1
Points: 23, Level: 1 Points: 23, Level: 1 Points: 23, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I have started like this, Im not sure is this the best approach to do this, having trouble of accessing the value of <UserLoginName> element now.

My XSL


Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />

	<xsl:template match="/">
		<TTC xmlns="http://ttc/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
			<UserAuthRequest>
			<UserLoginName>
					<xsl:apply-templates select="TTC/UserAuthRequest/UserLoginName" />
				</UserLoginName>
			</UserAuthRequest>
		</TTC>
	</xsl:template>

	<xsl:template match="TTC/UserAuthRequest/UserLoginName">
			 <xsl:copy>
			 	<xsl:apply-templates select="text()" /> 
			 </xsl:copy>
	</xsl:template>
</xsl:stylesheet>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert this xml file into Target xml file using XSLT sudheer2250 XSLT 6 June 10th, 2011 01:46 PM
Create XML file - add elements according to range remya1000 XML 5 October 3rd, 2007 02:50 PM
Creating Target Elements with Namespaces alapati.sasi XSLT 1 April 11th, 2007 05:31 AM
Replacing elements name while grouping. ROCXY XSLT 3 January 6th, 2006 01:11 PM
How to replace elements(from existed XML file)? hbcontract XML 1 October 30th, 2003 05:49 AM



All times are GMT -4. The time now is 04:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.