Reputation: 33
I am stuck with a XSL transformation and I've tried many things all day long. Obviously I am not an expert on this.
Can you help me to understand what's wrong with my XSL file ?
This is my source XML.
<?xml version="1.0" encoding="UTF-8"?>
<PublishPFTEST xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2017-08-18T17:20:13-03:00" transLanguage="EN" baseLanguage="EN" messageID="7584270.1503087614245122357" maximoVersion="7 6 20161014-1020 V7606-50" event="1">
<PFTESTSet>
<WORKORDER action="Add">
<ASSETNUM>MPC1234</ASSETNUM>
<DESCRIPTION>WOTEST</DESCRIPTION>
<WONUM>WO123</WONUM>
<SITEID>BEDFORD</SITEID>
</WORKORDER>
</PFTESTSet>
</PublishPFTEST>
My XSL file:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns="http://www.ibm.com/maximo" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<TemplateSet>
<xsl:for-each select="/PublishPFTEST/PFTESTSet/WORKORDER">
<asset>
<xsl:value-of select="ASSETNUM"/>
</asset>
<desc>
<xsl:value-of select="DESCRIPTION"/>
</desc>
</xsl:for-each>
<xsl:apply-templates/>
</TemplateSet>
</xsl:template>
</xsl:stylesheet>
And this is the transformed XML file... It shows other data, and no XML tags.
<?xml version="1.0" encoding="utf-8"?>
<TemplateSet xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
MPC1234
WOTEST
WO123
BEDFORD
</TemplateSet>
Sorry for the dummy question.
Upvotes: 2
Views: 2346
Reputation: 1
I had the same problem which was caused by multiple entries in the Transformation Pipeline in Eclipse. Just remove the duplicate and/or multiple entries and leave just the single one you need. Worked for me!
Upvotes: -1
Reputation: 52888
All of the text is showing up in the output because of XSLT's built-in template rules. To resolve that issue, you should remove the <xsl:apply-templates/>
so no other processing is done.
There are no new XML elements output because your xsl:for-each
never selects anything. This is because your XML is using the default namespace http://www.ibm.com/maximo
. You can bind that namespace to a prefix and use it in your XPath's.
Example of both suggestions (I also added exclude-result-prefixes="m"
so the namespace wouldn't be output)...
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:m="http://www.ibm.com/maximo"
exclude-result-prefixes="m">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<TemplateSet>
<xsl:for-each select="/m:PublishPFTEST/m:PFTESTSet/m:WORKORDER">
<asset>
<xsl:value-of select="m:ASSETNUM"/>
</asset>
<desc>
<xsl:value-of select="m:DESCRIPTION"/>
</desc>
</xsl:for-each>
</TemplateSet>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2