Extend XSLT with C # or Javascript

Source: Internet
Author: User
Tags cdata xsl xslt umbraco

I saw this article on umbraca today.ArticleYou can use C # and JavaScript to expand XSLT. To be honest, I didn't know it before. A few days ago, I saw a blogger implementing a split method and using the original XSLT function, now, you can program a split function.

The following describes how to use C # and JavaScript to expand XSLT:

I. Use C #

FirstCode:

<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype XSL: stylesheet [<! Entity nbsp "& # x00a0;">]>
<XSL: stylesheet
Version = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform%22
Xmlns: MSXML = "urn: Schemas-Microsoft-com: XSLT"
Xmlns: msxsl = "urn: Schemas-Microsoft-com: XSLT"
Xmlns: umbraco. Library = "urn: umbraco. Library"
Xmlns: mycustomprefix = "urn: mycustomprefix"
Exclude-result-prefixes = "MSXML umbraco. LibraryMycustomprefix msxsl">
 

<XSL: output method = "XML" omit-XML-declaration = "yes"/>

<Msxsl: script language = "CSHARP" implements-Prefix = "mycustomprefix">
<! [CDATA [
Public Int? Testnumber (Int? Num)
{
If (Num> 5 | num <= 0 | num = NULL)
{
Return 5;
}
Else
{
Return num;
}
}
]>
</Msxsl: SCRIPT>

<XSL: Param name = "currentpage"/>
 

<XSL: variable name = "numbertotest" select = "mycustomprefix: testnumber (number (/macro/numbertotest)"/>
<XSL: template match = "/">
<! -- Start writing XSLT -->
<XSL: value-of select = "$ numbertotest"/>
</XSL: Template>
</XSL: stylesheet>

The code above implementsTestnumberFunction. If the input value is greater than 5, 5 is returned. If the input value is less than 5, a value is returned. The example is very simple. It is clear at a glance that it will not bring a lot of space for colleagues who like XSLT.

Ii. use JavaScript

 

<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype XSL: stylesheet [<! Entity nbsp "& # x00a0;">]>
<XSL: stylesheet
Version = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform%22
Xmlns: MSXML = "urn: Schemas-Microsoft-com: XSLT"
Xmlns: msxsl = "urn: Schemas-Microsoft-com: XSLT"
Xmlns: umbraco. Library = "urn: umbraco. Library"
Xmlns: mycustomprefix = "urn: mycustomprefix"
Exclude-result-prefixes = "MSXML umbraco. LibraryMycustomprefix msxsl">
 

<XSL: output method = "XML" omit-XML-declaration = "yes"/>

<Msxsl: script language = "JavaScript" implements-Prefix = "mycustomprefix">
<! [CDATA [
Function testnumber (Num)
{
If (Num> 5 | num <= 0 | num = NULL)
{
Return 5;
}
Else
{
Return num;
}
}
]>
</Msxsl: SCRIPT>

<XSL: Param name = "currentpage"/>
<XSL: variable name = "numbertotest" select = "mycustomprefix: testnumber (number (/macro/numbertotest)"/>
<XSL: template match = "/">
<! -- Start writing XSLT -->
<XSL: value-of select = "$ numbertotest"/>
</XSL: Template>
</XSL: stylesheet>

Just like C #.

 

Now we can implement the split function, right? You don't need the substring-before or substring-after.

Link to that article: http://www.cnblogs.com/jaxu/archive/2009/11/16/1603756.html

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.