<?xml version="1.0" encoding="utf-8"?>
<Report p1:schemaLocation="Customer details http://reportserver?%2fCustomer details&rs%3aFormat=XML&rc%3aSchema=True" Name="Customer details" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance" xmlns="Customer details">
<table2>
<Detail_Collection>
<Detail Col1="aaa" col1_SeqID="2" col1_Include="1"
Col2="aaa" col2_SeqID="1" col2_Include="1"
Col3="aaa" col3_SeqID="" col3_Include="0"
Col4="aaa" col4_SeqID="4" col4_Include="1"
Col5="aaa" col5_SeqID="" col5_Include="0"
... ... ...
... ... ...
... ... ...
Col50="aaa" col50_SeqID="3" col50_Include="1"
/>
<Detail_Collection>
</table2>
</Report>
The above xml is produced by SSRS for the RDL file. I want to transform the above xml file to CSV format using XSLT (customized format). The RDL file (SSRS report) is very simple with 50 columns, and displays the data for all the columns depending on the user selection on the user interface. The user interface has got the parameter selection for all the 50 columns (i.e they can select the order of the column, they can select a particular column to be included on the report or not, the fontstyle etc...). As mentioned the each column has 2 main functionalities i.e. they can be sorted and as well ordered by based on the selections.
For example from the report output i.e in the xml format given above you will see all the 50 columns exist on the xml format but I am also including the extra fiedls which are generally hided on the report.
The col1 is included on the report and is ordered (seqID) as the 2nd column on the csv file. The col2 is also included on the report and is ordered as the 1st column on the csv file. The col3 is not included on the report and the order selection is empty, so this is not included on the csv file. ... ... like wise the col50 is included on the report but is ordered in as 3rd column in the csv file.
My main challenge here to create the xslt file for "CSV" and put the columns in the order selection which are selected per user basis.
The output in the CSV file after transformation will look as follows:
Col2 Col1 Col50 Col4
... ... ... ....
Any good idea to create this kind of xsl file is much appreciated and I thank you so much for understanding my question and trying to help me in this regard.
I. This XSLT 1.0 transformation:
when applied on this XML document (the provided one, made well-formed and unambiguous):
produces the wanted, correct result:
Explanation:
__
is equivalent to the XPath 2.0 expression:
.2. Appropriate use of
<xsl:sort>
,substring()
,name()
andcurrent()
..3. Using the fact that a string
$s
is castable to number if and only if:__
II. XSLT 2.0 solution:
when this transformation is applied on the same XML document (above), the same correct result is produced:
Update: @desi has asked that the heading should also be generated.
Here is the updated XSLT 1.0 transformation (as indicated, @desi is limited to use XSLT 1.0 only) that does this:
When this transformation is applied on the same XML document (above), the wanted, correct result is produced: