String value not available in javascript

After linking to the following two links, I created a javascript function in an XSL template. Javascript receives a call and a warning appears. But the CountID value becomes empty in the warning, although it does matter in html.

What change do we need to make to warn the counter?

Note. This is in an ASP.Net project, and I am using Visual Studio 2005 Note. This is an existing project, and I'm new to XSLT (although I have knowledge of javascript, xml, kendoui, html5, etc.).

LITERATURE

Javascript

  <SCRIPT LANGUAGE="javascript" DEFER="true"> var myVar = "<xsl:value-of select="CountID"/>"; <xsl:comment> function on_change() { alert(myVar); } </xsl:comment> </SCRIPT> 

XML source

 <ROOT> <Counts> <CountID>34rrgt56</CountID> <PlantCD>01</PlantCD> <CountType>PI</CountType> <StatusCD>OP</StatusCD> <EntryCompleteIND>N</EntryCompleteIND> <StartedBy>Lijo C</StartedBy> <CreatedOnDate>05/09/2014 00:19:04</CreatedOnDate> </Counts> </ROOT> 

Note. This XML is passed to the custom control, where it performs some additional additions. However, for this question this xml should be sufficient.

Full stylish XSL table

 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:template match="/"> <SCRIPT LANGUAGE="javascript" DEFER="true"> var myVar = "<xsl:value-of select="CountID"/>"; <xsl:comment> function on_change() { alert(myVar); } </xsl:comment> </SCRIPT> <div> <TABLE border="0" cellPadding="0" cellSpacing="0" BGCOLOR="#E5DBE2" width="100%"> <TR> <TD CLASS="Heading3" ALIGN="LEFT" WIDTH="25%"> <xsl:value-of select="/ROOT/Labels/PhysicalInventoryIDText/." /> </TD> <TD CLASS="Heading3" ALIGN="LEFT" WIDTH="20%"> <xsl:value-of select="/ROOT/Labels/DateTimeText/." /> <BR/> <xsl:value-of select="ROOT/Labels/StartedText/." /> </TD> <TD CLASS="Heading3" ALIGN="LEFT" WIDTH="15%"></TD> </TR> </TABLE> <TABLE style="display:none" name="emailTable" id="emailTable" width="100%" BGCOLOR="#E5DBE2"> <TR> <TD width="25%" CLASS="Normal" colspan="1" ALIGN="RIGHT"> <B> <xsl:value-of select="/ROOT/Labels/EmailAddressText/." /> </B> </TD> <TD width="75%" ALIGN="LEFT"> <img src="../Images/ArrowInvisible.gif" width="15" height="13" name="imgEmail1" /> <INPUT id="txtEmail1" name="txtEmail1" runat="server" width="100px" maxlength="100" Required="true" onfocus="document.forms[0].imgEmail1.src='../Images/ArrowVisibleDB.gif';" onblur="document.forms[0].imgEmail1.src='../Images/ArrowInvisible.gif';" /> </TD> </TR> <TR> <TD width="25%" CLASS="Normal" colspan="1" ALIGN="RIGHT"> <B> <xsl:value-of select="/ROOT/Labels/EmailAddressText/." /> </B> </TD> <TD width="75%" ALIGN="LEFT"> <img src="../Images/ArrowInvisible.gif" width="15" height="13" name="imgEmail2" /> <INPUT id="txtEmail2" name="txtEmail2" runat="server" width="100px" maxlength="100" Required="true" onfocus="document.forms[0].imgEmail2.src='../Images/ArrowVisibleDB.gif';" onblur="document.forms[0].imgEmail2.src='../Images/ArrowInvisible.gif';" /> </TD> </TR> </TABLE> <TABLE border="0" cellPadding="0" cellSpacing="0" BGCOLOR="#E5DBE2" width="100%"> <xsl:for-each select="ROOT/Counts"> <TR> <TD CLASS="Normal" ALIGN="LEFT" width="25%"> <xsl:value-of select="CountID"/> </TD> <TD CLASS="Normal" ALIGN="LEFT" width="20%" style="font-size:12"> <xsl:value-of select="CreatedOnDate"/> </TD> <TD ALIGN="RIGHT" width="15%"> <Input type="button"> <xsl:attribute name="id"> <xsl:value-of select="CountID"/> </xsl:attribute> <xsl:attribute name="name"> <xsl:value-of select="CountID"/> </xsl:attribute> <xsl:attribute name="onclick"> <xsl:text>on_change()</xsl:text> </xsl:attribute> <xsl:attribute name="value">Conclude</xsl:attribute> </Input> </TD> </TR> <xsl:if test="LastError!=''"> <TR> <TD COLSPAN="3" CLASS="Normal" ALIGN="LEFT" width="100%"> Last Error: <xsl:value-of select="LastError"/> </TD> </TR> </xsl:if> <TR style="display:none"> <xsl:attribute name="id"> row<xsl:value-of select="CountID" /> </xsl:attribute> <TD class="NormalError" colspan="4"> <xsl:value-of select="/ROOT/Labels/PIConcludeWarning/." /> <Input type="button" > <xsl:attribute name="value"> <xsl:value-of select="/ROOT/Labels/YesText/." /> </xsl:attribute> <xsl:attribute name="onclick"> submitForm(this,this.form,'<xsl:value-of select="CountID"/>') </xsl:attribute> </Input> <xsl:text disable-output-escaping="yes">&#160;</xsl:text> <Input type="button" > <xsl:attribute name="value"> <xsl:value-of select="/ROOT/Labels/CancelText/." /> </xsl:attribute> <xsl:attribute name="onclick"> window.row<xsl:value-of select="CountID" />.style['display'] = 'none';window.emailTable.style['display'] = 'none'; </xsl:attribute> </Input> </TD> </TR> <TR HEIGHT="1"> <TD BGCOLOR="#FFFFFF" COLSPAN="6" height="1"> <NOBR/> </TD> </TR> </xsl:for-each> </TABLE> </div> </xsl:template> </xsl:stylesheet> 
+1
source share
1 answer

The correct approach in terms of XSLT coding, in my opinion, is to write an XSLT code template, but since you have one template, it all starts with a replacement

  <Input type="button"> <xsl:attribute name="id"> <xsl:value-of select="CountID"/> </xsl:attribute> <xsl:attribute name="name"> <xsl:value-of select="CountID"/> </xsl:attribute> <xsl:attribute name="onclick"> <xsl:text>on_change()</xsl:text> </xsl:attribute> <xsl:attribute name="value">Conclude</xsl:attribute> </Input> 

with

 <input type="button" id="{CountID}" name="{CountID}" onclick="on_change(this.id);" value="Conclude"/> 

then make the Javascript function such that instead of the parameter

  var myVar = "<xsl:value-of select="CountID"/>"; <xsl:comment> function on_change() { alert(myVar); } </xsl:comment> 

just use

 <script type="text/javascript"> function on_change(id) { alert(id); } </script> 

That is all that is needed.

+1
source

Source: https://habr.com/ru/post/1333286/


All Articles