XML to XML Mapping using XSLT

Mogx21

New Member
I am new to XSLT and trying to map one XML to another XML using xslt, here is my first XML\[code\]<root> <record> <element name="LoginId">a</element> <element name="name">Admin Manager</element> <element name="password">12345</element> <element name="Age">28</element> <element name="Sex">M</element> </record> <record> <element name="LoginId">b</element> <element name="name">HR exec</element> <element name="password">pass1</element> <element name="Age">26</element> <element name="Sex">F</element> </record> <record> <element name="LoginId">c</element> <element name="name">PR Manager</element> <element name="password">pass2</element> <element name="Age">27</element> <element name="Sex">M</element> </record></root>\[/code\]I need to convert this XML to the following\[code\]<?xml version="1.0" encoding="UTF-8"?><final> <test> <UID>a</UUID> <Name>HR manager</Name> <Groups>admingroup</Groups> <Password>12345</Password> </test> <test> <UID>b</UUID> <Name>HR exec</Name> <Groups>admingroup</Groups> <Password>pass1</Password> </test> <test> <UID>c</UUID> <Name>PR manager</Name> <Groups>admingroup</Groups> <Password>pass2</Password> </test></final>\[/code\]i tried following xslt for transformation\[code\]<?xml version="1.0" encoding="UTF-8" ?> - <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">- <xsl:template match="/">- <test>- <xsl:for-each select="root/record"> <xsl:apply-templates select="element" /> </xsl:for-each> </test> </xsl:template>- <xsl:template match="element">- <test> <Employee /> - <UID> <xsl:value-of select="@LoginId" /> </UID>- <xsl:choose>- <xsl:when test="@name = ''">- <Name> <xsl:text>demo employee</xsl:text> </Name> </xsl:when>- <xsl:eek:therwise>- <Name> <xsl:value-of select="@name" /> </Name> </xsl:eek:therwise> </xsl:choose>- <Groups> <xsl:text>admingroup</xsl:text> </Groups>- <Password> <xsl:value-of select="@password" /> </Password> </test> </xsl:template> </xsl:transform>\[/code\]but this xslt is generating following XML output\[code\]<?xml version="1.0" encoding="UTF-8"?><impex> <final> <Employee /> <UID /> <Name>LoginId</Name> <Groups>admingroup</Groups> <Password /> </final>total 15 <final></final> with similar output\[/code\]i can do it easily in Java but some how have to do in xslt and only problem i am facing is the repetition of \[code\]<element>\[/code\] tag with different attribute valuesany help in this regard will be much helpful for me
 
Top