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