正在做的一个项目用到了xsl,刚才碰到了自定义变量的问题,就在这里贴一下:
 
1.直接使用select赋值:
 
  
  1. <xsl:variable name="变量名" select="'变量值'" />  
  2. 要注意的是,如果值是string类型,要加上引号,   可以 select="'变量值'",也可以select='"变量值"' 
2.包含在起始符中
 
 
  
  1. <xsl:variable name="变量名">  
  2.   <div>我是div<div>  
  3. </xsl:variable>  
给一个例子:
 
 
 
  
  1. <?xml version="1.0" encoding="ISO-8859-1"?>  
  2. <xsl:stylesheet version="1.0"  
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  4. <xsl:variable name="divTest">  
  5.   <tr>  
  6.   <th>Element</th>  
  7.   <th>Description</th>  
  8.   </tr>  
  9. </xsl:variable>  
  10. <xsl:template match="/">  
  11.   <html>  
  12.   <body>  
  13. <xsl:copy-of select="$divTest" />  
  14.   </body>  
  15.   </html>  
  16. </xsl:template>  
  17. </xsl:stylesheet>