I have a XSL file which has Javascript function which does XSL Transformation of data retrieved from DB, and pass it to a variable in XSL.
When I try to call the javascript function BuildXMLFieldAttributes from inside a xsl:variable, LabelStyleAttributes it works in IE but not in Firefox or Safari.
How to call a javascript function from inside a XSL:Variable and store the return value? Is it possible or not?
Any help on this will be very much appriciated. Desperately in need of help. Sample code is given below for your reference.
Sample XSL file:
<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:
js="urn:the-xml-files:xslt">
<ms:script language="Javascript" implements-prefix="
js" >
<![CDATA[
function BuildXMLFieldAttributes(xmlField,strXMLAttributes)
{
//var XMLAttributes = new ActiveXObject("Microsoft.XMLDOM"); //For IE
//XMLAttributes.loadXML(strXMLAttributes); //For IE
var XMLAttributes = new XMLHttpRequest(); //For Firefox or Safari
var oParser = new DOMParser();
XMLAttributes = oParser.parseFromString("strXMLAttributes", "text/xml");
return XMLAttributes;
}
]]>
</ms:script>
<xsl:output indent="yes"/>
<xsl:variable name="Components" select="Components/Component/row"></xsl:variable>
<xsl:template match="/">
<xsl:for-each select="$Components">
<xsl:variable name="LabelStyleAttributes" select="
js:BuildXMLFieldAttributes(current(),strin g(@LabelStyles))"/>
<div class="tabletxt" style="height:150px;border:solid 1px black;">
<xsl:call-template name="BuildComponent"/>
</div>
</xsl:for-each>
</xsl:template>
<xsl:template name="BuildComponent">
<div id="lbl_{@FieldID}_{$lblCounterIdx}" nowrap='' class="tabletxt" style="position:absolute;width:{@iLabelWidth}px;he ight:{@iLabelHeight}px;top:{@iLabelTop}px;left:{@i LabelLeft}px;">
<xsl:element name="LABEL">
<xsl:attribute name="id">
<xsl:value-of select="concat('lbl_',@FieldID)"/>
</xsl:attribute>
<xsl:call-template name="ApplyAttributes">
<xsl:with-param name="Attributes" select="$LabelStyleAttributes/Attribute"/>
</xsl:call-template>
<xsl:value-of select="@iLabelDesc"/>
</xsl:element>
</div>
</xsl:template>
<xsl:template name="ApplyAttributes">
<xsl:param name="Attributes"/>
<xsl:for-each select="$Attributes">
<xsl:attribute name="{@Name}">
<xsl:value-of select="@Value"/>
</xsl:attribute>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sample XML file:
<?xml version="1.0" encoding="UTF-16"?>
<Components>
<Component>
<row TableName="LNAPPRSEARCH" FieldID="3608" FieldName="Loan Amount" FieldValue="" DescName="Loan Amount" iLeft="556" iTop="271" iHeight="50" iWidth="155" TypeTableUse="0" iControlType="0" iGroupId="0" GroupName="Loan Amount" iLabelDisplay="1" iLabelDesc="Loan Amount" iLabelLeft="362" iLabelTop="196" iLabelWidth="155" iLabelHeight="50" GrpIdentity="0" iCompTypeId="0" iReadonly="0" DataType="Float" iValidateType="0" blVerify="0" iRights="2" RecId="0" LabelStyles="<Attribute Name="Style" Value="FONT-FAMILY:Garamond; FONT-SIZE:15;" />" LoanId="164857" />
</Component>
</Components>