XSLT½Ì³Ì

XSLT <xsl:value-of> ÔªËØ
2007-3-30

·µ»Ø

Definition and Usage
¶¨ÒåºÍÓ÷¨

The <xsl:value-of> element extracts the value of a selected node.
<xsl:value-of> ÔªËØµÄ×÷ÓÃÊÇ£ºÌáȡһ¸öÖ¸¶¨½ÚµãµÄÖµ¡£

The <xsl:value-of> element can be used to select the value of an XML element and add it to the output.
<xsl:value-of>ÔªËØµÄ×÷ÓÃÊÇ£ºÑ¡ÔñÒ»¸öXMLÔªËØµÄÖµ²¢½«ÆäÌí¼Óµ½Êä³öÎĵµÖС£

Note: The value of the required select attribute contains an XPath expression. It works like navigating a file system where a forward slash (/) selects subdirectories.
×¢Ò⣺±ØÒªµÄselect[Ñ¡Ôñ]ÊôÐÔÖµ°üº¬ÁËÒ»¸öXPath±í´ïʽ¡£ËüµÄÔËÐз½Ê½Èçͬһ¸öÎļþ²Ù×÷ϵͳ£¬¸ÃϵͳÄÚͨ¹ýÔÚÇ°Ãæ¼ÓÉÏб¸Ü£¨/£©À´Ñ¡Ôñ×ÓĿ¼¡£


Syntax
Óï·¨

<xsl:value-of
select="expression"
disable-output-escaping="yes|no"/>

Attributes
ÊôÐÔ

ÊôÐÔ Öµ

ÃèÊö

select expression Required. An XPath expression that specifies which node/attribute to extract the value from
±ØÒª²ÎÊý¡£Ö¸¶¨Ò»¸öXPath±í´ïʽ£¬¸Ã±í´ïʽÊÇÓÃÓÚÖ¸Ã÷´ÓÄĸö½Úµã/ÊôÐÔÖÐÌáȡֵ¡£
disable-output-escaping yes
no
Optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "&lt;". Default is "no"
¿ÉÑ¡²ÎÊý¡£Èç¹ûÉèÖÃΪ"yes"£¬ÔòÖ¸¶¨Á˾ßÌå×Ö·û£¨È磺“<”£©ÒÔÆä±¾ÉíÐÎʽÊä³ö£»Èç¹ûÉèÖÃΪ"no"£¬ÔòÖ¸¶¨Á˾ßÌå×Ö·û£¨È磺“<”£©±ØÐë×÷Ϊ"&lt;"Êä³ö¡£Ä¬ÈÏΪno

Example 1
°¸Àý1

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
 <html>
 <body>
   <h2>My CD Collection</h2>

   <table border="1">
     <tr bgcolor="#9acd32">
       <th>Title</th>
       <th>Artist</th>

     </tr>
     <tr>
      <td><xsl:value-of select="catalog/cd/title"/></td>
      <td><xsl:value-of select="catalog/cd/artist"/></td>

     </tr>
   </table>
 </body>
 </html>
</xsl:template>
</xsl:stylesheet>

²é¿´XML Îļþ¡¢XSL ÎļþÒÔ¼°½á¹û¡£

Example 2
°¸Àý2

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">

      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>

      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>

      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

²é¿´XML Îļþ¡¢XSL ÎļþÒÔ¼°½á¹û¡£

 

·µ»Ø