A newbie to the forum and the world of XML/XSLT
I'm trying to create a XSLT script to convert from one XML format to another (cXML is the target format) for a system integration project.
I want to be able to map values in the source XML tags to the destination cXML tags as necessary but am stumbling on problems retrieving the right elements
Here comes the code...
Source XML to be converted
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="UTF-8"?>
- <PublishMXPO_GOSOP xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2010-07-07T10:22:53+01:00" transLanguage="EN" baseLanguage="EN" messageID="1278494573441131060" maximoVersion="7 1 20090627-0754 V7115-149" event="0">
- <MXPO_GOSOPSet>
- <PO>
- <BILLTO>BAKEWELL</BILLTO>
- <BILLTOATTN>PMPRBOWNUSR</BILLTOATTN>
- </PO>
- </MXPO_GOSOPSet>
- </PublishMXPO_GOSOP>
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-8"?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- version="1.0" xmlns:xalan="http://xml.apache.org/xslt">
- <xsl:output method="xml" version="1.0" doctype-system="http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd" indent="yes"/>
- <xsl:variable name="version">1.2.020</xsl:variable>
- <xsl:template match="/PublishMXPO_GOSOP">
- <xsl:apply-templates select="PublishMXPO_GOSOP"/>
- </xsl:template>
- <xsl:template match="*">
- <xsl:variable name="messageID" select="@messageID"/>
- <xsl:variable name="timestamp" select="@creationDateTime"/>
- <xsl:variable name="version" select="$version"/>
- <cXML payloadID="{$messageID}" timestamp="{$timestamp}" version="{$version}" >
- <BILLADDRESS><xsl:value-of select="*"/></BILLADDRESS>
- <BILLTOPERSON><xsl:value-of select="PublishMXPO_GOSOP/MXPO_GOSOPSet/PO/BILLTOATTN"/></BILLTOPERSON>
- </cXML>
- </xsl:template>
- </xsl:stylesheet>
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd">
- <cXML xmlns:xalan="http://xml.apache.org/xslt" version="1.2.020" timestamp="2010-07-07T10:22:53+01:00" payloadID="1278494573441131060">
- <BILLADDRESS>
- BAKEWELL
- PMPRBOWNUSR
- </BILLADDRESS>
- <BILLTOPERSON/>
- </cXML>
I've only managed to get anything returned from the source XML file by using xsl:value-of select="*". Using an XPATH expression like in <BILLTOATTN> does not work
Also, when I change the first template-match statement to / from /PublishMXPO_GOSOP I lose everything in the conversion except the xml version encoding header? I thought this should select all the nodes in the whole document?
Any advice on this is really appreciated
Cheers
Eugene