XML to XML transformation
Posted: Sat Jan 03, 2015 1:20 pm
Hi Guys,
First of all I would like to say hello. I have some major problem (major for me but for some of you this should be a piece of cake).
I have an XML which looks like this:
======================================================================================
<?xml version="1.0"?>
<jderesponse>
<update>
<tables>
<table tablename="ClientCardPosition"/>
</tables>
<condition>
<cond tablename="ClientCardPosition" fieldname="ClientCardPosition-Gr" op="=" value="1"/>
<cond tablename="ClientCardPosition" fieldname="ClientCardPosition-Nr" op="=" value="2150000581"/>
<cond tablename="ClientCardPosition" fieldname="Numer-pozycji" op="=" value="1"/>
</condition>
<fields>
<ClientCardPosition>
<Status-JDE>ERROR</Status-JDE>
<Status-Text>Data-od wcześniejsza od daty zadziałania interfejsu, czyli 2.1.2015</Status-Text>
</ClientCardPosition>
</fields>
</update>
</jderesponse>
======================================================================================
I want to transform it using XSL file to receive such result :
======================================================================================
<?xml version="1.0"?>
<jderesponse>
<update>
<tables>
<table tablename="ClientCardPosition"/>
</tables>
<condition>
<cond tablename="ClientCardPosition" fieldname="klucz" op="=" value="Marged value from all three positions and this is 121500005811"/>
</condition>
<fields>
<ClientCardPosition>
<Status-JDE>Value from Status-JDE element which is "ERROR" </Status-JDE>
<Status-Text>Value from Status-Text element which is "Data-od wcześniejsza od daty zadziałania interfejsu, czyli 2.1.2015"</Status-Text>
</ClientCardPosition>
</fields>
</update>
</jderesponse>
======================================================================================
Could you please help with writing such XSL ?
What I have already is this :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:var="urn:var"
xmlns:user="urn:user"
xmlns:syncml="SYNCML:SYNCML1.1"
exclude-result-prefixes="msxsl var user syncml"
version="1.0">
<xsl:template match="jderesponse/update">
<update>
<tables>
<table tablename="ClientCardPosition"/>
</tables>
<condition>
<cond tablename="ClientCardPosition" fieldname="klucz" op="="
value=""/>
</condition>
<fields>
<ClientCardPosition>
<Status-JDE><xsl:value-of select="fields/ClientCardPosition/Status-JDE"/></Status-JDE>
<Status-Text><xsl:value-of select="fields/ClientCardPosition/Status-Text"/></Status-Text>
</ClientCardPosition>
</fields>
</update>
</xsl:template>
</xsl:stylesheet>
First of all I would like to say hello. I have some major problem (major for me but for some of you this should be a piece of cake).
I have an XML which looks like this:
======================================================================================
<?xml version="1.0"?>
<jderesponse>
<update>
<tables>
<table tablename="ClientCardPosition"/>
</tables>
<condition>
<cond tablename="ClientCardPosition" fieldname="ClientCardPosition-Gr" op="=" value="1"/>
<cond tablename="ClientCardPosition" fieldname="ClientCardPosition-Nr" op="=" value="2150000581"/>
<cond tablename="ClientCardPosition" fieldname="Numer-pozycji" op="=" value="1"/>
</condition>
<fields>
<ClientCardPosition>
<Status-JDE>ERROR</Status-JDE>
<Status-Text>Data-od wcześniejsza od daty zadziałania interfejsu, czyli 2.1.2015</Status-Text>
</ClientCardPosition>
</fields>
</update>
</jderesponse>
======================================================================================
I want to transform it using XSL file to receive such result :
======================================================================================
<?xml version="1.0"?>
<jderesponse>
<update>
<tables>
<table tablename="ClientCardPosition"/>
</tables>
<condition>
<cond tablename="ClientCardPosition" fieldname="klucz" op="=" value="Marged value from all three positions and this is 121500005811"/>
</condition>
<fields>
<ClientCardPosition>
<Status-JDE>Value from Status-JDE element which is "ERROR" </Status-JDE>
<Status-Text>Value from Status-Text element which is "Data-od wcześniejsza od daty zadziałania interfejsu, czyli 2.1.2015"</Status-Text>
</ClientCardPosition>
</fields>
</update>
</jderesponse>
======================================================================================
Could you please help with writing such XSL ?
What I have already is this :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:var="urn:var"
xmlns:user="urn:user"
xmlns:syncml="SYNCML:SYNCML1.1"
exclude-result-prefixes="msxsl var user syncml"
version="1.0">
<xsl:template match="jderesponse/update">
<update>
<tables>
<table tablename="ClientCardPosition"/>
</tables>
<condition>
<cond tablename="ClientCardPosition" fieldname="klucz" op="="
value=""/>
</condition>
<fields>
<ClientCardPosition>
<Status-JDE><xsl:value-of select="fields/ClientCardPosition/Status-JDE"/></Status-JDE>
<Status-Text><xsl:value-of select="fields/ClientCardPosition/Status-Text"/></Status-Text>
</ClientCardPosition>
</fields>
</update>
</xsl:template>
</xsl:stylesheet>