XSL自訂函數

來源:互聯網
上載者:User

標籤:style   http   使用   os   io   for   cti   代碼   

利用微軟的XSL的繼承特性,使用者可以自訂XSL函數.
基本原理是使用者寫的指令碼代碼寫在msxsl中,並設定這部分msxsl繼承到使用者自訂空間中,那麼使用者就可以通過使用者自訂空間使用msxsl中的指令碼代碼.

步驟:
1. xsl:stylesheet中定義msxml和使用者空間.
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0"
  xmlns:user="MyScript"
  其中xmlns:user=可以等於任意值

2. 讓msxsl繼承使用者空間.
  自訂函數寫在msxsl:script之間,並且加上implements-prefix="user"
  
例子:
-------------------------------------------------------------
1.xml
-------------------------------------------------------------
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type=‘text/xsl‘ href=‘1.xsl‘?>
<Book>
<Title>123</Title>
</Book>

-------------------------------------------------------------
1.xsl
-------------------------------------------------------------
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0"
xmlns:user="UserCode">
<msxsl:script language="VBScript" implements-prefix="user">
<![CDATA[ 
 Function GetName(node)
                   GetName = node.item(0).nodeName
 End Function  
]]>
</msxsl:script>
<xsl:template match="/">
 <xsl:value-of select="user:GetName(Book/Title)"/>
</xsl:template>
</xsl:stylesheet>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.