I want to translate an XML file with data like the following:
<FlatData>
<Details1_Collection>
<Details1 Customer1="Customer" Total1="3" />
...
</Details1_Collection>
</FlatData>
The data I am interested in is the attributes and their values in each Details1
. The problem is that these attributes are not necessarily going to be the same in every XML file I want to translate, and I want a general purpose XSL that could handle such Details1
as these:
<Details1 Customer1="Customer" Total1="3" />
<Details1 Name="Jim" Age="14" Weight="180" />
<Details1 Date="2009-07-27" Range="1-5" Option1="True" />
These different Details1
would not occur in the same source XML file, but rather in different files. However, I would like to use the same XSL on each.
I was thinking I needed something like <xsl:value-of select="@attribute_name"/>
but what do I put for @attribute_name
when I don't know beforehand what attributes there will be? Also, how do I capture the attribute name? I would like to explode the source XML above to something like:
<Details1>
<Customer1>Customer</Customer1>
<Total1>3</Total1>
</Details1>
Edit: thanks for the responses! I'm having trouble getting more than the following output, however:
<?xml version="1.0" encoding="UTF-8"?>
<FlatData>
<Details1_Collection></Details1_Collection>
</FlatData>
I've tried both lavinio's and Jörn Horstmann's answers, as well as trying to combine the two. I run this command:
msxsl.exe -o output.xml input.xml transform.xsl
I think something that's getting in the way is a namespace in the input file:
<Report Name="MyReport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="MyReport">