½ñÌìÔÚumbracaÉÏ¿´µ½ÕâÑùһƪÎÄÕÂ
£¬¿ÉÒÔÀûÓÃC#ºÍJavaScriptÀ©Õ¹XSLT
£¬ËµÊµÔڵģ¬ÒÔÇ°²»ÖªµÀ°
¡£¬Ç°¼¸Ìì¿´µ½ÓÐ벩Ö÷ʵÏÖÁËÒ»¸ösplit·½·¨£¬ÀûÓÃÔÓеÄxsltº¯Êý£¬ÏÖÔÚ¿´À´¿ÉÒÔÖ±½Ó
±à³ÌʵÏÖÒ»¸ösplitº¯ÊýÁËŶ
¡£ÏÂÃæ¿´ÏÂÔõôÓÃC#ºÍJavaScriptÀ©Õ¹XSLT£º
Ò»¡¢Ê¹ÓÃC#
ÏÈÉÏ´úÂ룺
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
<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.library mycustomprefix 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>
ÉÏÃæ´úÂëʵÏÖÁËÒ»¸ötestNumberº¯Êý£¬µ±ÊäÈëÊýÖµ´óÓÚ5ʱ·µ»Ø5£¬Ð¡ÓÚ5ʱ·µ»ØÊýÖµ¡£Àý×Ӻܼòµ¥£¬¿´Ò»ÑÛ¾ÍÃ÷ÁË£¬²»¹ýÈ¥¶Ôϲ»¶xsltµÄͬÈÊ´øÀ´ºÜ´óµÄ·¢»Ó
¿Õ¼äŶ¡£
¶þ¡¢ÓÃJavaScript
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
<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.library mycustomprefix 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>
ºÍʹÓÃC#Ò»Ñù£¬²»¶à˵ÁË
ÏÖÔھͿÉÒÔʵÏÖÄǸösplitº¯ÊýÁË£¬ÊÇ°É£¿²»ÓÃÄǸösubstring-beforeºÍsubstring-afterÁËŶ