XSLT <xsl:variable> ÔªËØ
¶¨ÒåºÍÓ÷¨
<xsl:variable> ÔªËØÓÃÓÚÉùÃ÷¾Ö²¿»òÈ«¾ÖµÄ±äÁ¿¡£
×¢ÊÍ£ºÈç¹û±»ÉùÃ÷Ϊ¶¥²ãÔªËØ£¬Ôò¸Ã±äÁ¿ÊÇÈ«¾ÖµÄ£¬¶øÈç¹ûÔÚÄ£°åÄÚÉùÃ÷£¬Ôò±äÁ¿ÊDZ¾µØµÄ¡£
×¢ÊÍ£ºÒ»µ©ÄúÉèÖÃÁ˱äÁ¿µÄÖµ£¬¾ÍÎÞ·¨¸Ä±ä»òÐ޸ĸÃÖµ£¡
Ìáʾ£ºÄú¿ÉÒÔͨ¹ý <xsl:variable> ÔªËØµÄÄÚÈÝ»òͨ¹ý select ÊôÐÔ£¬Ïò±äÁ¿Ìí¼ÓÖµ£¡
Óï·¨
<xsl:variable name="name" select="expression"> <!-- Content:template --> </xsl:variable>
ÊôÐÔ
ÊôÐÔ | Öµ | ÃèÊö |
---|---|---|
name | name | ±ØÐè¡£¹æ¶¨±äÁ¿µÄÃû³Æ¡£ |
select | expression | ¿ÉÑ¡¡£¶¨Òå±äÁ¿µÄÖµ¡£ |
ʵÀý
Àý×Ó 1
Èç¹ûÉèÖÃÁË select ÊôÐÔ£¬<xsl:variable> ÔªËØ¾Í²»Äܰüº¬ÈκÎÄÚÈÝ¡£Èç¹û select ÊôÐÔº¬ÓÐÎÄ×Ö×Ö·û´®£¬Ôò±ØÐë¸ø×Ö·û´®¼ÓÒýºÅ¡£
ÏÂÃæµÄÁ½¸öÀý×ÓΪ±äÁ¿ "color" ¸³Öµ "red"£º
<xsl:variable name="color" select="'red'"
/>
<xsl:variable name="color" select='"red"'
/>
Àý×Ó 2
Èç¹û <xsl:variable> ÔªËØÖ»°ü°üº¬ name ÊôÐÔ£¬ÇÒûÓÐÄÚÈÝ£¬Ôò±äÁ¿µÄÖµÊÇ¿Õ×Ö·û´®£º
<xsl:variable name="j" />
Àý×Ó 3
ÏÂÃæµÄÀý×Óͨ¹ý <xsl:variable> ÔªËØµÄÄÚÈÝΪ±äÁ¿ "header" ¸³Öµ£º
<?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="header">
<tr> <th>Element</th> <th>Description</th> </tr></xsl:variable>
<xsl:template match="/"> <html> <body> <table> <xsl:copy-of select="$header" /> <xsl:for-each select="reference/record"> <tr> <xsl:if category="XML"> <td><xsl:value-of select="element"/></td> <td><xsl:value-of select="description"/></td> </xsl:if> </tr> </xsl:for-each> </table> <br /> <table> <xsl:copy-of select="$header" /> <xsl:for-each select="table/record"> <tr> <xsl:if category="XSL"> <td><xsl:value-of select="element"/></td> <td><xsl:value-of select="description"/></td> </xsl:if> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>