Javascript code in XsltListViewWebPart Give parsing error
I am working with XsltListViewWebPart, I add my custom xsl and it works good.This xsl contain an anchor tag like that
<a>
<xsl:attribute name="title"><xsl:value-of select="@Title"/&g开发者_Go百科t;</xsl:attribute>
<xsl:attribute name="onclick"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:value-of select="@Title"/>
</a>
When I am trying to complete my javascript code it gives me parsing error. Here is my code
<a>
<xsl:attribute name="title"><xsl:value-of select="@Title"/></xsl:attribute>
<xsl:attribute name="onclick">OpenPopUpPage("/lists/news/dispform.aspx?isdlg=1&ID=<xsl:value-of select="@ID"/>");</xsl:attribute>
<xsl:value-of select="@Title"/>
</a>
Can any one help me, Please?
With XML (and XSLT is XML) you need to escape any ampersand '&' as '&'
so try
<a>
<xsl:attribute name="title"><xsl:value-of select="@Title"/></xsl:attribute>
<xsl:attribute name="onclick">OpenPopUpPage("/lists/news/dispform.aspx?isdlg=1&ID=<xsl:value-of select="@ID"/>");</xsl:attribute>
<xsl:value-of select="@Title"/>
</a>
or better yet use attribute value templates e.g.
<a title="{@Title}">
onclick="OpenPopUpPage('/lists/news/dispform.aspx?isdlg=1&ID={@ID}');">
<xsl:value-of select="@Title"/>
</a>
as it makes the code shorter and easier to read.
精彩评论