XSL Transformation not generating expected result after upgrade to .Net 2.0  
Author Message
Pai





PostPosted: XML and the .NET Framework, XSL Transformation not generating expected result after upgrade to .Net 2.0 Top

I am currently upgrading a .Net 1.1 project to .Net 2.0 and one of my XSLT is not generating the expected results. I even used the new XSLCompiledTransform object , didnot help much ..

Below is the XSL File , it takes in some parameters , does anyone know of any part of the XSL that is obsolete or so. Looks like <xsl:if> is not working ..

Any suggestions or comments are greatly appreciated.

< xml version="1.0" encoding="UTF-8" >

<xsl:stylesheet version="1.0" xmlns:xsl=" http://www.hide-link.com/ " xmlns:asp="remove">

<xsl:output method="html"/>

<xsl:template match="/">

<!--Parameter declaration-->

<xsl:param name="CurrentState"/> <!--Will determine rendition of control menu-->

<xsl:param name="AllowPersonalization"/> <!--Will determine rendition of control menu-->

<xsl:param name="WebPartType"/> <!--Will determine rendition of Content Pane-->

<xsl:param name="IsAdmin" /> <!--Will determine rendition of control menu-->

<xsl:param name="IsSharedView"/> <!--Will change the rendition of WebPart-->

<xsl:param name="ShowHelp" /> <!--Will determine rendition of control menu-->

<xsl:param name="IsUserWebPart" /> <!--Will determine rendition of control menu-->

<!--End of Parameter declaration-->

<!--Variable declaration-->

<xsl:variable name="AllowResize">

<xsl:value-of select=" "></xsl:value-of>

</xsl:variable>

<xsl:variable name="AllowRemove">

<xsl:value-of select=" "></xsl:value-of>

</xsl:variable>

<!--End of variable declaration-->

<DIV ID="ViewerRoot" style="padding-left:2px;padding-top:2px;padding-bottom:2px;padding-right:2px;display:block;">

<script>

function showControlMenu(e, MenuImageID)

{

var objMenuTable;

var posX = 0;

var posY = 0;

var sMenuID;

//Code to get the proper mouse coordinates based upon the browser.

if(window.event)

{

posX = window.event.x + window.document.body.scrollLeft - 200;

posY = window.event.y + window.document.body.scrollTop;

}

else

{

posX = e.pageX - 200;

posY = e.pageY;

}

sMenuID = MenuImageID.substring(0,MenuImageID.indexOf('PullMenu'));

objMenuTable = window.document.getElementById(sMenuID + 'CONTROLMENUTABLE');

if(objMenuTable)

{

objMenuTable.style.left = posX;

objMenuTable.style.top = posY;

objMenuTable.style.display = 'inline';

setTimeout("hideControlMenu('" + objMenuTable.id + "')", 5000);

}

}

function hideControlMenu(sMenuTable)

{

var objMenuTable;

objMenuTable = window.document.getElementById(sMenuTable);

if(objMenuTable)

{

objMenuTable.style.display = 'none';

}

}

function highlightMe(MenuItem)

{

MenuItem.style.background = 'white';

}

function doPostBack(ControlName)

{

__doPostBack(ControlName, '');

}

</script>

<TABLE cellspacing="0" cellpadding="0" border="0">

<xsl:attribute name="style">

<xsl:if test="$CurrentState = '3'">

height:<xsl:value-of select=" "></xsl:value-of>px;

</xsl:if>

width:<xsl:value-of select=" "></xsl:value-of>px;

<xsl:if test=" ">

<xsl:variable name="borderwidth" select=" "/>

<xsl:variable name="bordercolor" select=" "/>

border-top:<xsl:value-of select="$bordercolor"></xsl:value-of> solid <xsl:value-of select="$borderwidth"></xsl:value-of>px;

border-bottom:<xsl:value-of select="$bordercolor"></xsl:value-of> solid <xsl:value-of select="$borderwidth"></xsl:value-of>px;

border-left:<xsl:value-of select="$bordercolor"></xsl:value-of> solid <xsl:value-of select="$borderwidth"></xsl:value-of>px;

border-right:<xsl:value-of select="$bordercolor"></xsl:value-of> solid <xsl:value-of select="$borderwidth"></xsl:value-of>px;

</xsl:if>

</xsl:attribute>

<xsl:if test=" ">

<TR>

<td>

<table cellspacing="0" cellpadding="0" border="0">

<!--

The following width attribute has been added to ensure that the width

of the WebPart remains consistent to the user configured value regardless

of the state.

-->

<xsl:attribute name="width">

<xsl:value-of select=" "></xsl:value-of>px;

</xsl:attribute>

<tr valign="top">

<xsl:choose>

<xsl:when test=" ">

<!-- Use the Default Background Settings for the Title Bar -->

<TD ID="TITLEPANE">

<table cellspacing="0" cellpadding="0" border="0" width="100%">

<tr valign="center" style="height:20px">

<td style="background-color:#FFc20c;

font-family:arial, verdana;

color:#ffffff;

padding-left:2px;

width:15px;

font-size:10px;">&#160;</td>

<td style="background-color:#3B5C17;

font-family:verdana;

color:#ffffff;

padding-left:2px;

width:100%px;

font-size:10px;">&#160;

<b><xsl:value-of select=" "></xsl:value-of></b>

</td>

</tr>

</table>

</TD>

<TD ID="CONTROLMENU">

<xsl:attribute name="style">

cursor:pointer;

background-color:#3B5C17;

width:15px;

color:#FFc20c;

</xsl:attribute>

<SPAN style="font-family:webdings;" onclick="showControlMenu(event, this.id);" id="PullMenu" runat="server">6</SPAN>

</TD>

<!-- End of Default Background Settings for the Title Bar -->

</xsl:when>

<xsl:otherwise>

<!-- Use the Custom Background Settings for the Title Bar -->

<TD ID="TITLEPANE">

<xsl:attribute name="style">

background-color:<xsl:value-of select=" "></xsl:value-of>;

font-family:<xsl:value-of select=" "></xsl:value-of>;

color:<xsl:value-of select=" "></xsl:value-of>;

padding-left:2px;

height:15px;

width:<xsl:value-of select=" "></xsl:value-of>px;

font-size:10px;

</xsl:attribute>

<b><xsl:value-of select=" "></xsl:value-of></b>

</TD>

<TD ID="CONTROLMENU">

<xsl:attribute name="style">

cursor:pointer;

background-color:<xsl:value-of select=" "></xsl:value-of>;

width:15px;

color:<xsl:value-of select=" "></xsl:value-of>;

</xsl:attribute>

<SPAN style="font-family:webdings;" onclick="showControlMenu(event, this.id);" id="PullMenu" runat="server">6</SPAN>

</TD>

<!-- End of Custom Background Settings for the Title Bar -->

</xsl:otherwise>

</xsl:choose>

</tr>

</table>

</td>

</TR>

</xsl:if>

<xsl:if test="$CurrentState = 3">

<TR ID="CONTENTROW" valign="top">

<TD colspan="2">

<xsl:attribute name="style">

width:<xsl:value-of select=" "></xsl:value-of>px;

height:<xsl:value-of select=" "></xsl:value-of>px;

</xsl:attribute>

<asp:label ID="CONTENTPANE" runat="server">

<xsl:attribute name="style">

width:<xsl:value-of select=" "></xsl:value-of>px;

height:<xsl:value-of select=" "></xsl:value-of>px;

<xsl:choose>

<xsl:when test="$WebPartType = 'URL'">

<!-- commented to avoid the scroll appearing on a WebPart -->

<!--overflow:hidden;-->

</xsl:when>

<xsl:when test="$WebPartType = 'ReportViewer'">

<!-- commented to avoid the scroll appearing on a WebPart -->

<!--overflow:hidden;-->

</xsl:when>

<xsl:otherwise>

<xsl:choose>

<xsl:when test=" ">

<!-- commented to avoid the scroll appearing on a WebPart -->

<!--overflow:hidden;-->

</xsl:when>

<xsl:otherwise>

<!-- commented to avoid the scroll appearing on a WebPart -->

<!--overflow:scroll;-->

</xsl:otherwise>

</xsl:choose>

</xsl:otherwise>

</xsl:choose>

</xsl:attribute>

</asp:label>

</TD>

</TR>

</xsl:if>

</TABLE>

<DIV ID="CONTROLMENUTABLE" style="display:none;position:absolute;left:0px;top:0px;" runat="server" width="200px">

<TABLE border="0" cellpadding="0" cellspacing="0" width="200px">

<xsl:attribute name="style">

font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;

font-weight: normal;

background-color: <xsl:value-of select=" "></xsl:value-of>;

vertical-align:middle;

height:25px;

border-color:black;

border-top:white 1px solid;

border-bottom:black 1px solid;

border-left:white 1px solid;

border-right:black 1px solid;

</xsl:attribute>

<!-- Display the Modify Shared View link only to the Admin Users -->

<xsl:if test="$IsAdmin='true' and $IsUserWebPart = false">

<TR onmouseover="highlightMe(this);" valign="top">

<xsl:attribute name="onmouseout">

this.style.background = '<xsl:value-of select=" "></xsl:value-of>';

</xsl:attribute>

<xsl:attribute name="style">

text-decoration:none;

color:<xsl:value-of select=" "></xsl:value-of>;

</xsl:attribute>

<TD style="width:10%">

<xsl:attribute name="style">

border-right:black 1px solid;

</xsl:attribute>

<SPAN>

<xsl:attribute name="style">

padding-right:2px;

padding-left:2px;

font-family:webdings;

width:100%;

color:<xsl:value-of select=" "></xsl:value-of>;

</xsl:attribute>

</SPAN>

</TD>

<TD nowrap="true" style="width:90%">

<asp:LinkButton ID="mnuEditSharedProp" runat="server" Text="Modify Shared Properties" autopostback="false" CausesValidation="false">

<xsl:attribute name="style">

text-decoration:none;

color:<xsl:value-of select=" "></xsl:value-of>;

font-family:<xsl:value-of select=" "></xsl:value-of>;

font-size:10px;

</xsl:attribute>

</asp:LinkButton>

</TD>

</TR>

</xsl:if>

<xsl:if test="$ShowHelp='true'">

<TR onmouseover="highlightMe(this);" valign="top">

<xsl:attribute name="onmouseout">

this.style.background = '<xsl:value-of select=" "></xsl:value-of>';

</xsl:attribute>

<xsl:attribute name="style">

cursor:pointer;

text-decoration:none;

color:<xsl:value-of select=" "></xsl:value-of>;

</xsl:attribute>

<TD style="width:10%">

<xsl:attribute name="style">

border-right:black 1px solid;

</xsl:attribute>

<SPAN>

<xsl:attribute name="style">

padding-right:2px;

padding-left:2px;

font-family:webdings;

width:100%;

color:<xsl:value-of select=" "></xsl:value-of>;

</xsl:attribute>

s

</SPAN>

</TD>

<TD nowrap="true" style="width:90%">

<asp:LinkButton ID="mnuHelp" runat="server" Text="Help" autopostback="false" CausesValidation="false">

<xsl:attribute name="style">

text-decoration:none;

color:<xsl:value-of select=" "></xsl:value-of>;

font-family:<xsl:value-of select=" "></xsl:value-of>;

font-size:10px;

</xsl:attribute>

</asp:LinkButton>

</TD>

</TR>

</xsl:if>

</TABLE>

</DIV>

</DIV>

</xsl:template>

</xsl:stylesheet>

Thanks

Ganesh




.NET Development3  
 
 
Dimitre_Novatchev - MSFT





PostPosted: XML and the .NET Framework, XSL Transformation not generating expected result after upgrade to .Net 2.0 Top

Simply stating: "The xslt transformation is not working" is not going to help -- it is like saying: "Doctor, I'm not feeling well..."

Please, provide a complete (but the minimal possible) code example that consists of the source xml file(s), the xslt file(s), the expected result, the result produced and an explanation of what constitutes the unwanted difference of behavior.

Cheers,
Dimitre Novatchev.


 
 
Martin Honnen





PostPosted: XML and the .NET Framework, XSL Transformation not generating expected result after upgrade to .Net 2.0 Top

If those parameters like CurrentState are supposed to be global parameters that can be set from outside of the stylesheet before the transformation is being run then you need to include them as top level elements, as direct children of the xsl:stylesheet element e.g.

<xsl:stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:param name="CurrentState"/>

Your stylesheet defines those parameters inside of a template and that way they are not global and cannot be set from outside of the stylesheet. XslTransform in .NET 1.x is unfortunately buggy in this regardance but for XslCompiledTransform in .NET 2.0 the placement of xsl:param matters.



 
 
Pai





PostPosted: XML and the .NET Framework, XSL Transformation not generating expected result after upgrade to .Net 2.0 Top

I apologize for not giving enough information , Below is the C# Code , XML document , XSL Argument value and the output of XSL Transformation in VS 2003 and VS 2005 , If you closely look at the XSL output in 2003 , there is a label called "CONTENTPANE " but this is not rendered in VS 2005.

Thanks

Ganesh

XML
-------

<VIEWERPROPS><CAT ID= "appearanceProps " TEXT= "General Appearance "><PROP TEXT= "Allow Resize " ID= "AllowResize " TYPE= "Combo " ADMIN= "1

" DEFAULT= "1 " VALUE= "1 "><VALUES><ADD TEXT= "Yes " VALUE= "1 "></ADD><ADD TEXT= "No " VALUE= "0 "></ADD></VALUES></PROP><PROP TEXT= "Allow

Remove " ID= "AllowRemove " TYPE= "Combo " ADMIN= "1 " DEFAULT= "1 " VALUE= "1 "><VALUES><ADD TEXT= "Yes " VALUE= "1 "></ADD><ADD TEXT= "No "

VALUE= "0 "></ADD></VALUES></PROP><PROP TEXT= "Default Height " ID= "Height " TYPE= "text " ADMIN= "0 " DEFAULT= "100 " VALUE= "500

"></PROP><PROP TEXT= "Default Width " ID= "Width " TYPE= "text " ADMIN= "0 " DEFAULT= "100 " VALUE= "975 "></PROP><PROP TEXT= "Show

Scrollbars " ID= "ShowScrollbars " TYPE= "Combo " ADMIN= "0 " DEFAULT= "0 " VALUE= "0 "><VALUES><ADD TEXT= "Yes " VALUE= "1 "></ADD><ADD

TEXT= "No " VALUE= "0 "></ADD></VALUES></PROP></CAT><CAT ID= "borderProps " TEXT= "Border Settings "><PROP TEXT= "Show Border " ID=

"ShowAttribute " TYPE= "Combo " ADMIN= "0 " DEFAULT= "1 " VALUE= "0 "><VALUES><ADD TEXT= "Yes " VALUE= "1 "></ADD><ADD TEXT= "No " VALUE= "0

"></ADD></VALUES></PROP><PROP TEXT= "Width " ID= "BorderWidth " TYPE= "text " ADMIN= "0 " DEFAULT= "100 " VALUE= "1 "></PROP><PROP TEXT=

"Color " ID= "BorderColor " TYPE= "text " ADMIN= "0 " DEFAULT= "#999966 " VALUE= "#999966 "></PROP></CAT><CAT ID= "titleProps " TEXT= "Title

Bar Settings "><PROP TEXT= "Visible " ID= "ShowTitle " TYPE= "Combo " ADMIN= "0 " DEFAULT= "1 " VALUE= "0 "><VALUES><ADD TEXT= "Yes " VALUE=

"1 "></ADD><ADD TEXT= "No " VALUE= "0 "></ADD></VALUES></PROP><PROP TEXT= "Title " ID= "Title " TYPE= "text " ADMIN= "1 " DEFAULT= "Portlet

Title " VALUE= "My Title "></PROP><PROP TEXT= "Background Color " ID= "TitleBGColor " TYPE= "text " ADMIN= "1 " DEFAULT= "#f7f7c6 " VALUE=

"#f7f7c6 "></PROP><PROP TEXT= "Font Type " ID= "TitleFontType " TYPE= "text " ADMIN= "1 " DEFAULT= "verdana " VALUE= "Arial "></PROP><PROP

TEXT= "Font Color " ID= "FontColor " TYPE= "text " ADMIN= "1 " DEFAULT= "black " VALUE= "black "></PROP></CAT><CAT ID= "DATASOURCE "><CAT ID=

"CustomControlProps " TEXT= "Custom Control Properties "><PROP TEXT= "Assembly Name " ID= "AssemblyName " TYPE= "text " ADMIN= "1 " DEFAULT=

"SIBCUSTOMCONTROLS.dll " VALUE= "SIBCUSTOMCONTROLS.dll "></PROP><PROP TEXT= "Class Name " ID= "ClassName " TYPE= "text " ADMIN= "1 " DEFAULT=

"SIB.INFOBASE.WEB.CustomControls.Login " VALUE= "SIB.INFOBASE.WEB.CustomControls.Login "></PROP></CAT></CAT></VIEWERPROPS>


XSL Arguments Value
--------------

CurrentState = 3

AllowPersonalization = False

WebPartType = "CustomControl"

IsAdmin = False

IsSharedView = False

ShowHelp = False

IsUserWebPart = False

C# Code
----------------------------------------------------------------------------------------------------

using nsSysXml = System.Xml;
using nsSysIO = System.IO;

protected string Transform(string XSLString, string XMLString, nsSysXml.Xsl.XsltArgumentList XSLArguments)
{
//Load the XML and XSL in memory streams.
nsSysIO.StringReader objXmlReader = new nsSysIO.StringReader(XMLString);
nsSysIO.StringReader objXslReader = new nsSysIO.StringReader(XSLString);

nsSysXml.XPath.XPathDocument xdXmlDoc;
nsSysXml.XPath.XPathDocument xdXslDoc;
nsSysXml.Xsl.XslTransform xtTransform = new nsSysXml.Xsl.XslTransform();

//Create the output stream for Transformed XML.
nsSysIO.StringWriter objOutXml = new nsSysIO.StringWriter();

try
{
//Create the XMLDocument object for XML and XSL.
xdXmlDoc = new nsSysXml.XPath.XPathDocument(objXmlReader);
xdXslDoc = new nsSysXml.XPath.XPathDocument(objXslReader);

xtTransform.Load(xdXslDoc, null, null);


//Transform the XML.
xtTransform.Transform(xdXmlDoc, XSLArguments, objOutXml, null);

return objOutXml.ToString();
}
finally
{
//Close all the open streams.
if (objXmlReader != null)
{
objXmlReader.Close();
}

if (objXslReader != null)
{
objXslReader.Close();
}

if (objOutXml != null)
{
objOutXml.Close();
}

objXmlReader = null;
objXslReader = null;
xdXmlDoc = null;
xdXslDoc = null;
xtTransform = null;
objOutXml = null;
}
}


--XSL Transformation Result in 2003
----------------------------------------------

<DIV ID= "ViewerRoot " style= "padding-left:2px;padding-top:2px;padding-bottom:2px;padding-right:2px;display:block; " xmlns:asp= "remove ">
<script>

function showControlMenu(e, MenuImageID)
{ var objMenuTable;
var posX = 0;
var posY = 0;
var sMenuID;
//Code to get the proper mouse coordinates based upon the browser.
if(window.event)
{ posX = window.event.x + window.document.body.scrollLeft - 200;
posY = window.event.y + window.document.body.scrollTop;

}
else
{
posX = e.pageX - 200;
posY = e.pageY;
}
sMenuID = MenuImageID.substring(0,MenuImageID.indexOf('PullMenu'));
objMenuTable = window.document.getElementById(sMenuID + 'CONTROLMENUTABLE');
if(objMenuTable)
{
objMenuTable.style.left = posX;
objMenuTable.style.top = posY;
objMenuTable.style.display = 'inline';
setTimeout( "hideControlMenu(' " + objMenuTable.id + "') ", 5000);
}
}


function hideControlMenu(sMenuTable)
{
var objMenuTable;
objMenuTable = window.document.getElementById(sMenuTable);
if(objMenuTable)
{
objMenuTable.style.display = 'none';
}
}

function highlightMe(MenuItem)
{
MenuItem.style.background = 'white';

}


function doPostBack(ControlName)
{
__doPostBack(ControlName, '');
}

</script>

<TABLE cellspacing= "0 " cellpadding= "0 " border= "0 " style= " height:500px; width:975px; ">
<TR ID= "CONTENTROW " valign= "top ">
<TD colspan= "2 " style= " width:975px; height:485px; ">
<asp:label ID= "CONTENTPANE" runat= "server " style= " width:975px; height:485px; ">

</asp:label>
</TD>
</TR>
</TABLE>

<DIV ID= "CONTROLMENUTABLE " style= "display:none;position:absolute;left:0px;top:0px; " runat= "server " width= "200px ">
<TABLE border= "0 " cellpadding= "0 " cellspacing= "0 " width= "200px " style= " font-family: Tahoma, Verdana, Arial, Helvetica,

sans-serif; font-size: 8pt; font-weight: normal; background-color: #f7f7c6; vertical-align:middle; height:25px;

border-color:black; border-top:white 1px solid; border-bottom:black 1px solid; border-left:white 1px solid;

border-right:black 1px solid; ">
</TABLE>
</DIV>
</DIV>

XSL Transformation Result in 2005
------------------------------------------------

<DIV ID="ViewerRoot" style="padding-left:2px;padding-top:2px;padding-bottom:2px;padding-right:2px;display:block;" xmlns:asp="remove">
<script>
function showControlMenu(e, MenuImageID)
{
var objMenuTable;
var posX = 0;
var posY = 0;
var sMenuID;

//Code to get the proper mouse coordinates based upon the browser.
if(window.event)
{
posX = window.event.x + window.document.body.scrollLeft - 200;
posY = window.event.y + window.document.body.scrollTop;
}
else
{
posX = e.pageX - 200;
posY = e.pageY;
}

sMenuID = MenuImageID.substring(0,MenuImageID.indexOf('PullMenu'));
objMenuTable = window.document.getElementById(sMenuID + 'CONTROLMENUTABLE');

if(objMenuTable)
{
objMenuTable.style.left = posX;
objMenuTable.style.top = posY;
objMenuTable.style.display = 'inline';
setTimeout("hideControlMenu('" + objMenuTable.id + "')", 5000);
}

}

function hideControlMenu(sMenuTable)
{
var objMenuTable;
objMenuTable = window.document.getElementById(sMenuTable);

if(objMenuTable)
{
objMenuTable.style.display = 'none';
}
}

function highlightMe(MenuItem)
{
MenuItem.style.background = 'white';
}

function doPostBack(ControlName)
{
__doPostBack(ControlName, '');
}
</script>


<TABLE cellspacing="0" cellpadding="0" border="0" style="
width:975px;
">
</TABLE>
<DIV ID="CONTROLMENUTABLE" style="display:none;position:absolute;left:0px;top:0px;" runat="server" width="200px">
<TABLE border="0" cellpadding="0" cellspacing="0" width="200px" style="
font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;
font-weight: normal;
background-color: #f7f7c6;
vertical-align:middle;
height:25px;
border-color:black;
border-top:white 1px solid;
border-bottom:black 1px solid;
border-left:white 1px solid;
border-right:black 1px solid;
">
</TABLE>
</DIV>
</DIV>



 
 
Martin Honnen





PostPosted: XML and the .NET Framework, XSL Transformation not generating expected result after upgrade to .Net 2.0 Top

You need to make sure the XSLT parameter that you want to set from outside of the stylesheet are defined as top level elements in the stylesheet.

 
 
Pai





PostPosted: XML and the .NET Framework, XSL Transformation not generating expected result after upgrade to .Net 2.0 Top

Thanks a lot Martin.

 
 
-Anton Lapounov





PostPosted: XML and the .NET Framework, XSL Transformation not generating expected result after upgrade to .Net 2.0 Top

Hello Ganesh,

It was actually a bug that it worked in .NET Framework 1.1:

BUG: Local XSLT parameter values are overwritten when executing an XSLT Transformation in .NET Framework v1.1

The XSLT implementation in .NET Framework 2.0 is much more compliant with the W3C XSLT 1.0 specification. Please fix the stylesheet; that way it will work not only with the old XslTransform processor, but with other XSLT engines as well. Sorry for the inconvenience.

Best regards,
Anton Lapounov