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 December 2nd, 2015, 11:18 AM
Authorized User
 
Join Date: Nov 2015
Posts: 12
Thanks: 4
Thanked 0 Times in 0 Posts
Default Need to pass a value in output XML based on a tag value in input XML using XSLT

Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<RECORDS>
<Group>
<Name>12345</Name>
<Grp>MANAGER</Grp>
<FName>Alex</FName>
<LName>Johnson</LName>
<String1>abcd</String1>
</Group>
<Group>
<Name>67891</Name>
<Grp>PROJECT MANAGER</Grp>
<FName>JAMES</FName>
<LName>HARPER</LName>
<String1></String1>
</Group>
</RECORDS>
</DATA>


Requirement:

In output XML

If String1 has a value then Type tag should have value as "axbx" and if String1 is blank then Type tag should have value as "dydy"

<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<RECORDS>
<Group>
<Name>12345</Name>
<Grp>MANAGER</Grp>
<FName>Alex</FName>
<LName>Johnson</LName>
<Type>axbx</Type>
</Group>
<Group>
<Name>67891</Name>
<Grp>PROJECT MANAGER</Grp>
<FName>JAMES</FName>
<LName>HARPER</LName>
<Type>dydy</Type>
</Group>
</RECORDS>
</DATA>


I just need help with the transformation of the Type tag in output XML based on value in String1 in input XML. Please suggest.
 
Old December 2nd, 2015, 01:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This seems pretty basic.

...If String1 has a value then Type tag should have value as "axbx" and if String1 is blank then Type tag should have value as "dydy"

Code:
<xsl:template match="String1[. != '']">
  <Type>axbx</Type>
</xsl:template>

<xsl:template match="String1[. = '']">
  <Type>dydy</Type>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting elements accessed via apply-templates based on the real XML tag name in XSLT azikh XSLT 2 August 29th, 2013 07:56 PM
xml flat file transform to nested tag xml using xslt transform adsingh XSLT 0 August 7th, 2013 01:27 PM
XSLT for converting column based xml to row based one sayusekhar XSLT 4 March 8th, 2011 08:20 AM
How to force XSLT to output a close tag in XML? richcon XSLT 2 June 29th, 2006 02:39 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM





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