Apply JavaScript/C # script and so on in XSL

Source: Internet
Author: User
Tags cdata xsl
By Ben
For example, XML: <root> <item> abcdefabcdeabcdef </item> </root> requires XSL to be written to convert the XML. All B in the content of item in the output must be changed to B, normal XSL cannot be completed

How to embed Javascript:XSL: <? XML version = "1.0" encoding = "gb2312"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform"Xmlns: msxsl = "urn: Schemas-Microsoft-com: XSLT"
Xmlns: myns = "urn: mynamespace">
<Msxsl: script language = "jscript" implements-Prefix = "myns">
<! [CDATA [
Function trans (s)
{
VaR ary = S. Split ('B ');
Return ary. Join ('B ');
}
]>
</Msxsl: SCRIPT>
<XSL: template match = "/">
<XSL: Apply-templates select = "// root/item"/>
</XSL: Template> <XSL: template match = "root/item">
<XSL: value-of select ="Myns: Trans (string (.))"/>
</XSL: Template>
</XSL: stylesheet>

What do you think?

The script can be C # Instead of JScript #: <Msxsl: script language = "C #" implements-Prefix = "myns">
<! [CDATA [
Public String trans (string S)
{
String [] ary = S. Split ('B ');
Return string. Join ('B', Ary );
}
]>
</Msxsl: SCRIPT> but it can only be parsed using system. xml of. NET Framework, rather than MSXML commonly used by clients.

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.