Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2012, 10:10 AM
Registered User
 
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.
 
Old May 16th, 2012, 10:17 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old May 16th, 2012, 10:21 AM
Registered User
 
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.
 
Old May 16th, 2012, 10:31 AM
Registered User
 
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>





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





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