View Single Post
  #3 (permalink)  
Old June 14th, 2010, 10:35 AM
sivakumar_g01 sivakumar_g01 is offline
Registered User
 
Join Date: Jun 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using XSLT to transform one XML format to other

Hi Martin,

I think i have misled your answer because of my little experience with XSLT,not sure whether i can make use of this in my scenario.. I am trying to put my actual scenario. Actually i have source and target xsds and have to use xslt to convert from one xsd formatted XML to another xsd formatted XML.

Source XSD:
<xsd:complexType name="CreateUserAttr">
<xsd:sequence>
<xsd:element name="value" type="DsmlValue"/>
</xsd:sequence>
<xsd:attribute name="name" type="CreateUserDescValue" use="required"/>
</xsd:complexType>

<xsd:complexType name="UserInput">
<xsd:sequence>
<xsd:element name="attr" type="CreateUserAttr"/>
</xsd:sequence>
</xsd:complexType>

<xsd:element name="UserInput" type="UserInput"/>


Target XSD:
<xsd:complexType name="Input">
<xsd:sequence>
<xsd:element name="UserCode" type="xsd:string"/>
<xsd:element name="Password" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="CreateUser" type="Input"/>

So to do this i am creating the xstl like below. And in if scenario i dont want to hard code it to 'UserCode' or 'Password' and wants to use use any in built function, so that i will be able to extend my xsds in future without worrrying about xslt Xformation. Please let me know how can i get the UserCode element name in if condition below. I was unable to refer any target element in xslt if condition.

<xsl:template match="/">
<ns1:CreateUser>
<xsl:for-each select="/ns0:UserInput/ns0:attr">
<xsl:if test="@name = 'UserCode'">
<ns1:UserCode>
<xsl:value-of select="ns0:value"/>
</ns1:UserCode>
</xsl:if>
</xsl:for-each>
</ns1:UserCreateInput>
</xsl:template>

Thanks
Siva
Reply With Quote