This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Generic Lookup (Element Mapping)



Hi everyone,

I have been trying to write a generic xslt template to map the element names
based on a lookup table.
The lookup xml file has always a subset of the elements and therefore I do
not want to hard code the element names.
The output file is a flat xml file in opposite to the input file.

I have done the part of the key (or at least I think) like

<xsl:variable name="xmlMap" select="document('Lookup.xml')"/>
<xsl:key name="lookup" match="Maps/Map"
use="concat(generate-id(),':',SEname,':',SAname,':',TEname)"/>

But my main problem is how navigate through the input file in a generic
approach.
I'm also just a little concern about the overall performance because the
input file might be MBs big.

I would appreciate any help,

Thanks,
Faroukh

----------------------------
data.xml (input)
<project>
	<aa1>
		<aa11>aa11_value</aa11>
		<aa12>aa12_value</aa12>
		<aa13>aa13_value</aa13>
		<aa2>
			<aa21>aa21_value</aa21>
			<aa22>aa22_value</aa22>
			<aa3>
				<aa31>aa31_value></aa31>
				<aa4>
					<aa41>aa41_value></aa41>
				</aa4>
			</aa3>
		</aa2>
	</aa1>

	<aa1>
	<!-- .............. -->
	</aa1>
</project>

Lookup.xml (It contains the names of the element in the input file and the
matching names in the output)
<Maps>
	<Map>						<!-- combination of SEName, SAname and TEname is unique through
the file.
		<SEname>aa1</SEname>		<!--  element name in the input file
		<SAname>aa11</SAname>		<!-- element name in the input file, it's always
the child element of SEName
		<TEname>aa_1</TEname>		<!-- element name in output
		<TAname>aa_11</TAname>		<!-- element nemae in output, it should be the
child element of TEname
	</Map>
	<Map>
		<SEname>aa1</SEname>
		<SAname>aa12</SAname>
		<TEname>aa_1</TEname>
		<TAname>aa_12</TAname>
	</Map>
	<Map>
		<SEname>aa1</SEname>
		<SAname>aa13</SAname>
		<TEname>aa_1A</TEname>
		<TAname>aa_13</TAname>
	</Map>
	<Map>
		<SEname>aa2</SEname>
		<SAname>aa21</SAname>
		<TEname>aa_2</TEname>
		<TAname>aa_21</TAname>
	</Map>
<!-- no mapping for aa22 -->
	<Map>
		<SEname>aa3</SEname>
		<SAname>aa31</SAname>
		<TEname>aa_3</TEname>
		<TAname>aa_31</TAname>
	</Map>
</Maps>

The output should look like:
<project>
	<aa_1>
		<aa_11>aa11_value</aa_11>
		<aa_12>aa12_value</aa_12>
	</aa_1>
	<aa_1A>		<!-- Elelment aa_1 in the source has been mapped to two elements
(aa_1 and aa_1A) in the target-->
		<aa_13>aa11_value</aa_13>
	</aa_1A>
	<aa_2>
		<aa_2>aa21_value</aa_2>
	</aa_2>
	<aa_3>
		<aa_3>a31_value</aa_3>
	</aa_3>
	<aa_1>
		<!-- ................. -->
	</aa_1>
</project>




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]