Here is a sample of the XML that I am starting with:

XML: any.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="any.xsl"?>
    <root>
	<device>
		<device_Info>
			<name>Name 1</name>
			<type>Type</type>
		</device_Info>
		<drive_Pair>
			<status>Ready</status>
			<Local>
				<l_name>10E5</l_name>
			</Local>
			<Remote>
				<l_name>0651</l_name>
			</Remote>
		</drive_Pair>
                #Can be 1 or many <drive_Pair>'s
		{<drive_Pair>
			...
		</drive_Pair>}
                # Can only be 1 Totals
		<Totals>
			<Local>
				<l1_invalid_mbs>0.0</l1_invalid_mbs>
				<l2_invalid_mbs>0.0</l2_invalid_mbs>
			</Local>
		</Totals>
	</device>
       #Can be 1 or many <device>'s
	{<device>
               ...
	</device>}
    </root>

XSL: any.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" standalone="yes" cdata-section-elements="devices" indent="yes"/>
	<xsl:template match="/root/device">
		<xsl:element name="devices">
			<xsl:for-each select="device_Info">
				<device name="{name}" type="{type}"/>
			</xsl:for-each>
			<xsl:for-each select="drive_Pair">
				<drive_Pair status="{status}" local="{Local/l_name}" remote="{Remote/l_name}"/>
			</xsl:for-each>
			<xsl:for-each select="drive_Pair_Totals/Local">
				<Totals l1="{l1_invalid_mbs}" l2="{l2_invalid_mbs}"/>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

The XML Result: temp.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<devices>
	<device name="Name 1" type="backup"/>
	<drive_Pair status="same" local="1234" remote="1234"/>
	<drive_Pair status="same" local="4321" remote="4321"/>
	<Totals l1="0.0" l2="0.0"/>
</devices>
<devices>
	<device name="Name 2" type="Active"/>
	<drive_Pair status="different" local="3425" remote="3542"/>
	<drive_Pair status="different" local="0362" remote="9876"/>
        <drive_Pair status="same" local="8767" remote="8767"/>
	<Totals l1="0.0" l2="0.0"/>
</devices>

The issue I am having is when I validate the output XML, temp.xml it comes back with an error that happens right here (line 8 of temp.xml):

<Totals l1="0.0" l2="0.0"/>
</devices>
<devices>   #<--------- "Character 'D' is grammatically unexpected"
	<device name="Name 2" type="Active"/>

It references that the reason for the error is because it expects '!' or '?'.... And I am at a loss on how to "fix" it.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" standalone="yes" cdata-section-elements="devices" indent="yes"/>
	<xsl:template match="root">
		<devices>
			<xsl:apply-templates select="device"/>
		</devices>
	</xsl:template>

	<xsl:template match="device">
		<xsl:apply-templates select="device_Info"/>
		<xsl:apply-templates select="drive_Pair"/>
		<xsl:apply-templates select="Totals"/>
	</xsl:template>


	<xsl:template match="device_Info">
		<device name="{name}" type="{type}"/>
	</xsl:template>
	<xsl:template match="drive_Pair">
		<drive_Pair status="{status}" local="{Local/l_name}" remote="{Remote/l_name}"/>
	</xsl:template>


	<xsl:template match="Totals">
		<Totals l1="l1_invalid_mbs" l2="l2_invalid_mbs"/>
	</xsl:template>
</xsl:stylesheet>

Thanks for both replies, I had setup a rootElement earlier and It kept giving me another error... But thanks for pointing out the obvious and sending an example!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.