XSL Trouble: Output is missing root element



I've done a few XSL transformations in the past, but I seem to be out of my depth on this one. Through trial and error I've managed to get nearly the output I'm looking for, but I cannot figure out how to get a root element in my output.


Here is a sample of the XML file input. I need to weed out some unnecessary info and get inside that CDATA.



<SI_RESOURCES>
<SCHEDULES>
<SCHEDULE>
<SCHEDULE_TYPE>2</SCHEDULE_TYPE>
<ASSOCIATED_BP_NAME>AFTPurgeArchiveMailboxes</ASSOCIATED_BP_NAME>
<ASSOCIATED_SERVICE_NAME>AFTPurgeArchiveMailboxes</ASSOCIATED_SERVICE_NAME>
<SCHEDULE_PARAMS/>
<SCHEDULE_ONSTARTUP>1</SCHEDULE_ONSTARTUP>
<SCHEDULE_EXECUTION_COUNT>-1</SCHEDULE_EXECUTION_COUNT>
<SCHEDULE_EXECUTION_CURRENT_COUNT>0</SCHEDULE_EXECUTION_CURRENT_COUNT>
<SCHEDULE_EXECUTION_STATUS>WAIT</SCHEDULE_EXECUTION_STATUS>
<SCHEDULE_STATUS>ACTIVE</SCHEDULE_STATUS>
<SCHEDULE_SYSTEMNAME>node1</SCHEDULE_SYSTEMNAME>
<SCHEDULE_USERID>admin</SCHEDULE_USERID>
<SCHEDULE_TIMINGXML><![CDATA[<timingxml><days><day ofWeek="-1"><times><time>0400</time></times></day></days><excludedDates></excludedDates></timingxml>]]></SCHEDULE_TIMINGXML>
</SCHEDULE>
<SCHEDULE>
<SCHEDULE_TYPE>1</SCHEDULE_TYPE>
<ASSOCIATED_BP_NAME>Schedule_AssociateBPsToDocs</ASSOCIATED_BP_NAME>
<ASSOCIATED_SERVICE_NAME>AssociateBPsToDocs</ASSOCIATED_SERVICE_NAME>
<SCHEDULE_PARAMS/>
<SCHEDULE_ONSTARTUP>0</SCHEDULE_ONSTARTUP>
<SCHEDULE_EXECUTION_COUNT>-1</SCHEDULE_EXECUTION_COUNT>
<SCHEDULE_EXECUTION_CURRENT_COUNT>0</SCHEDULE_EXECUTION_CURRENT_COUNT>
<SCHEDULE_EXECUTION_STATUS>WAIT</SCHEDULE_EXECUTION_STATUS>
<SCHEDULE_STATUS>ACTIVE</SCHEDULE_STATUS>
<SCHEDULE_SYSTEMNAME>node1</SCHEDULE_SYSTEMNAME>
<SCHEDULE_USERID>admin</SCHEDULE_USERID>
<SCHEDULE_TIMINGXML><![CDATA[<timingxml><days><day ofWeek="-1"><times><timeRange><range>0000-2359</range><interval>30</interval><onMinute>0</onMinute></timeRange></times></day></days><excludedDates></excludedDates></timingxml>]]></SCHEDULE_TIMINGXML>
</SCHEDULE>
</SCHEDULES>
</SI_RESOURCES>


Here is my XSL so far. It's messy, and I'm not entirely sure how it works. I get no output when I use <xsl:template match="/"> and I'm not sure why. My only guess is that it has something to do with the CDATA.



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:template match="node()|@*">
<xsl:for-each select="SCHEDULE">
&lt;schedule&gt;
&lt;bp_name&gt;<xsl:value-of select="ASSOCIATED_BP_NAME"/>&lt;/bp_name&gt;
&lt;run_on_startup&gt;<xsl:value-of select="SCHEDULE_ONSTARTUP"/>&lt;/run_on_startup&gt;
&lt;status&gt;<xsl:value-of select="SCHEDULE_STATUS"/>&lt;/status&gt;
&lt;user&gt;<xsl:value-of select="SCHEDULE_USERID"/>&lt;/user&gt;
<xsl:value-of select="SCHEDULE_TIMINGXML"/>
&lt;/schedule&gt;
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>


I could use the resulting output if it had a root element, ie <schedules>, but I can't figure out how to get it over there. Can anyone point me in the right direction?


No comments:

Post a Comment