Application of script tag in XSLT

Source: Internet
Author: User
Tags httpcontext script tag xpath functions xslt

HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/533TEXSX (vs.71). aspx#y1338: View Application

 XSLT is applied to parsing XML files, and in asp.net programming, XML controls can be used to specify DocumentSource properties to load XML files. Specifies the TransformSource property to load the XSLT file, and the XML control automatically displays the converted results on the page. XSLT itself also supports many XPath functions, as well as some simple logical statements, such as If,choose-when-otherwise,for-each, and the other in XSLT You can also customize methods (called Templates in xslt ) to be repeatedly called by other code, and a detailed description of XSLT can refer to W3school's xslt tutorial.

Since the advent of Moss in Microsoft,XSLT has become more and more widely used, and sometimes we also encounter problems of interaction between XSLT and JavaScript and some server-side languages, such as the need to follow JavaScript code to determine whether to output content on the page, you need to use the msxsl:script tag in the XSLT .

The

Msxsl:script tag is supported by Microsoft, which itself can support several different languages, such as C # , Vb.net,jscript, and so on, specifically using the Methods and introductions can refer to the MSDN,HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/533TEXSX (vs.71). aspx. In addition, there is also an article detailing how to use the msxsl:script tag in xslt http:// Blog.joycode.com/saucer/archive/2004/05/12/21273.joy.

Basically, we are in XSLT can be directly using msxsl:script tags in Defined public methods and types, in the case of a server-side language, you must ensure that the method or type is common, and that the type of the parameter or return value must be the same when it is passed and received (some of the parameter types are in XSLT is not supported, and in most cases we might use to the nodelist type. Of course, when uses server-side languages, the assembly and namespace references are also necessary, and here's an example:
Code highlighting produced by Actipro Codehighlighter ( Freeware)
http://www. codehighlighter.com/

--><msxsl:script language= " C # " implements-prefix= "User" >
<msxsl:using namespace= "system.web"/>
<msxsl:assembly name= "system.web"/>
public bool Matchcurrurl (String loc)
{
return HttpContext.Current.Request.Url.ToString (). ToLower (). IndexOf (Loc. ToLower ())!=-1;
}
</msxsl:script>

Msxsl:using tags and msxsl:assembly tags are used to refer to namespaces and assemblies, respectively, and they can theoretically be written anywhere in the XSLT file. The msxsl:script tag is identified as the C # language, and the Matchcurrurl method uses to HttpContext global objects, This object is subordinate to the System.Web namespace, so you must add the assembly reference and namespace before use . Do not expect XSLT to automatically load assemblies and namespace references for you because the msxsl:script tag is not a standard for the consortium, and you must declare it before you use it, as in the following two lines:
The Code highlighting produced by Actipro Codehighlighter (freeware)
http://www. codehighlighter.com/

-->xmlns:msxsl= "urn:schemas-microsoft-com: xslt "
xmlns:user= "Urn:my-scripts"

If you are using a client language, such as JavaScript, in the msxsl:script tag, be careful to avoid using client browser objects, such as Windows, document, and so on, because XSLT itself is resolved on the server side, and the server does not know the behavior of the client , and the JavaScript code we write in the msxsl:script tag should be mapped into a server-side method to be parsed correctly. If you want to have access to the page address of the client during the interaction, the best way is to use it in C # HTTPCONTEXT.CURRENT.REQUEST.URL, instead of using document.location or window.location in JavaScript.

  using The msxsl:script tag eliminates a lot of hassle in the development process, and in traditional development habits, if we want to insert C # in XSLT code, it is generally done by writing the code in the user control and then outputting the reference token for the user control in the XSLT . If you use the msxsl:script tag directly, you can write all the C # code in it, eliminating the hassle of writing user controls.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.