I am having problems taking an xml report (in the format described below) and, using xsl, transform it into separately sortable tables that appear on the same page.
The stylesheet should transform the xml so that each project is its own table (and containing the project's rows), each attribute becomes a column of that table, and each table should be sortable by any attribute (column).
I had no problem getting the transform to output the data as desired, but I cannot figure out how to sort each table separately. All my efforts, produce the same outcome: if I click the column of one table, all tables are sorted.
Everything I am using that's relevant is listed below. I am sure everything except the XML will need to change. My experience with XSL is very limited, and I have been searching forever for this solution and am running out of time.
Thanks!
--------------------------
----------
----
XML Format:
<Report>
<Project Name="Project 1">
<Row AttributeA="1" AttributeB="2"/>
<Row AttributeA="3" AttributeB="4"/>
<Row AttributeA="5" AttributeB="6"/>
<Row AttributeA="7" AttributeB="8"/>
</Project>
<Project Name="Project 2">
<Row AttributeA="9" AttributeB="10"/>
<Row AttributeA="11" AttributeB="12"/>
<Row AttributeA="13" AttributeB="14"/>
<Row AttributeA="15" AttributeB="16"/>
</Project>
<Project Name="Project 3">
<Row AttributeA="17" AttributeB="18"/>
<Row AttributeA="19" AttributeB="20"/>
<Row AttributeA="21" AttributeB="22"/>
<Row AttributeA="23" AttributeB="24"/>
</Project>
</Report>
--------------------------
----------
----
XSL Format:
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//Project"/>
</xsl:template>
<xsl:template match="//Project">
<P>
<H2><xsl:value-of select="./@Name"/></H2>
<TABLE>
<TR>
<TH onClick="sort('./@Attribut
eA','text'
);">Attrib
uteA</TH>
<TH onClick="sort('./@Attribut
eB','text'
);">Atribu
teB</TH>
</TR>
<xsl:for-each select="./row">
<xsl:sort select="./@AttributeA" order="ascending" datatype="text"/>
<TR>
<TD><xsl:value-of select="./@AttributeA"/></
TD>
<TD><xsl:value-of select="./@AttributeB"/></
TD>
</TR>
</xsl:for-each>
</TABLE>
</P>
</xsl:template>
</xsl:stylesheet>
--------------------------
----------
----
Javascript:
function sort(sortBy,dataType)
{
// XSLObject is the stylesheet as a data island
// and is already loaded
var sortSelection = XSLObject.selectSingleNode
("//xsl:so
rt/@select
");
sortSelection.nodeValue = sortBy;
var sortOrder = XSLObject.selectSingleNode
("//xsl:so
rt/@order"
);
if (currentSortBy == sortBy)
{
if (sortOrder.nodeValue == "ascending")
{
sortOrder.nodeValue = "descending";
}
else
{
sortOrder.nodeValue = "ascending";
}
}
else
{
sortOrder.nodeValue = "ascending";
}
currentSortBy = sortBy;
var sortDateType = XSLObject.selectSingleNode
("//xsl:so
rt/@dataty
pe");
sortDateType.nodeValue = dataType;
//Existing function that does the transform
DoTransform();
}
--------------------------
----------
----
Start Free Trial