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