I'm trying convert this file:
<?xml version="1.0" encoding="utf-8"?>
<x12errors>
<header>
<errors>
<issue>
<message>Wrong value</message>
<path>path to bad value</path>
</issue>
<issue>
<message>Missing value</message>
<path>path where missing value should be</path>
</issue>
</errors>
<warnings>
<issue>
<message>Value too small</message>
<path>path to value</path>
</issue>
</warnings>
</header>
<boxes>
<box>
<boxName>cardboard</boxName>
<boxStyleNum>12345</boxStyleNum>
<errors>
<issue>
<message>Box too small</message>
<path>path to box size</path>
</issue>
</errors>
<warnings>
<issue>
<message>Box flaps off center</message>
<path>path to box measurements</path>
</issue>
</warnings>
<wrappings>
<wrapping>
<material>bubble wrap</material>
<dimensions>9x12</dimensions>
<errors>
<issue>
<message>Wrong material</message>
<path>path</path>
</issue>
</errors>
<warnings>
<issue>
<message>Prefer different color</message>
<path>path to value</path>
</issue>
</warnings>
</wrapping>
</wrappings>
</box>
</boxes>
</x12errors>
to this file:
<?xml version="1.0" encoding="utf-8"?>
<x12errors>
<header>
<headerMsg><type>E</type><msgText>Wrong value</msgText></headerMsg>
<headerMsg><type>E</type><msgText>Missing value</msgText></headerMsg>
<headerMsg><type>W</type><msgText>Value too small</msgText></headerMsg>
</header>
<boxes>
<box>
<boxName>cardboard</boxName>
<boxStyleNum>12345</boxStyleNum>
<boxMsg><type>E</type><msgText>Box too small</msgText></boxMsg>
<boxMsg><type>W</type><msgText>Box flaps off center</msgText></boxMsg>
<wrappings>
<wrapping>
<material>bubble wrap</material>
<dimensions>9x12</dimensions>
<wrappingMsg><type>E</type><msgText>Wrong material</msgText></wrappingMsg>
<wrappingMsg><type>E</type><msgText>Prefer different color</msgText></wrappingMsg>
</wrapping>
</wrappings>
</box>
</boxes>
</x12errors>
I have the following xsl file that's close, but it's leaving the "errors" and "warnings" tags in there and I can't figure out why! Can anyone help me?
Here's my current xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="no"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="header//errors/issue">
<xsl:apply-templates select="message"/>
</xsl:template>
<xsl:template match="header//errors/issue/message">
<headerMsg>
<type>E</type>
<xsl:element name="msgText">
<xsl:apply-templates />
</xsl:element>
</headerMsg>
</xsl:template>
<xsl:template match="header/warnings/issue">
<xsl:apply-templates select="message"/>
</xsl:template>
<xsl:template match="header//warnings/issue/message">
<headerMsg>
<type>W</type>
<xsl:element name="msgText">
<xsl:apply-templates />
</xsl:element>
</headerMsg>
</xsl:template>
<xsl:template match="boxs">
<xsl:apply-templates select="box"/>
</xsl:template>
<xsl:template match="box/errors/issue">
<xsl:apply-templates select="message"/>
</xsl:template>
<xsl:template match="box//errors/issue/message">
<boxMsg>
<xsl:apply-templates select="../../boxName"/>
<xsl:apply-templates select="../../boxStyle"/>
<type>E</type>
<xsl:element name="msgText">
<xsl:apply-templates />
</xsl:element>
</boxMsg>
</xsl:template>
<xsl:template match="box/warnings/issue">
<xsl:apply-templates select="message"/>
</xsl:template>
<xsl:template match="box//warnings/issue/message">
<boxMsg>
<xsl:apply-templates select="../../boxName"/>
<xsl:apply-templates select="../../boxStyle"/>
<type>W</type>
<xsl:element name="msgText">
<xsl:apply-templates />
</xsl:element>
</boxMsg>
</xsl:template>
<xsl:template match="wrappings">
<xsl:apply-templates select="wrapping"/>
</xsl:template>
<xsl:template match="wrapping/errors/issue">
<xsl:apply-templates select="message"/>
</xsl:template>
<xsl:template match="wrapping//errors/issue/message">
<wrappingMsg>
<xsl:apply-templates select="../../material"/>
<xsl:apply-templates select="../../dimensions"/>
<type>E</type>
<xsl:element name="msgText">
<xsl:apply-templates />
</xsl:element>
</wrappingMsg>
</xsl:template>
<xsl:template match="wrapping/warnings/issue">
<xsl:apply-templates select="message"/>
</xsl:template>
<xsl:template match="wrapping//warnings/issue/message">
<wrappingMsg>
<xsl:apply-templates select="../../material"/>
<xsl:apply-templates select="../../dimensions"/>
<type>W</type>
<xsl:element name="msgText">
<xsl:apply-templates />
</xsl:element>
</wrappingMsg>
</xsl:template>
</xsl:stylesheet>
Thanks! Laurie