XSLT <xsl:for-each> ÔªËØ

<xsl:for-each> ÔªËØÔÊÐíÄúÔÚ XSLT ÖнøÐÐÑ­»·¡£

<xsl:for-each> ÔªËØ

<xsl:for-each> ÔªËØ¿ÉÓÃÓÚѡȡָ¶¨µÄ½Úµã¼¯ÖеÄÿ¸ö XML ÔªËØ¡£

<?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>

×¢ÊÍ£ºselect ÊôÐÔµÄÖµÊÇÒ»¸ö XPath ±í´ïʽ¡£´Ë±í´ïʽµÄ¹¤×÷·½Ê½ÀàËÆÓÚ¶¨Î»Ä³¸öÎļþϵͳ£¬ÔÚÆäÖÐÕýб¸Ü¿ÉÑ¡Ôñ×ÓĿ¼¡£

ÉÏÃæµÄת»»½á¹ûÀàËÆÕâÑù£º

²é¿´´Ë XML Îļþ£¬²é¿´´Ë XSL Îļþ£¬²¢²é¿´½á¹û¡£

½á¹û¹ýÂË

ͨ¹ýÔÚ <xsl:for-each> ÔªËØÖÐÌí¼ÓÒ»¸öÑ¡ÔñÊôÐÔµÄÅбðʽ£¬ÎÒÃÇÒ²¿ÉÒÔ¹ýÂË´Ó XML ÎļþÊä³öµÄ½á¹û¡£

<xsl:for-each select="catalog/cd[artist='Bob Dylan']">

ºÏ·¨µÄ¹ýÂËÔËËã·û:

  • =  (µÈÓÚ)
  • != (²»µÈÓÚ)
  • &lt; (СÓÚ)
  • &gt; (´óÓÚ)
<?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[artist='Bob Dylan']">
   <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 Îļþ£¬²¢²é¿´½á¹û¡£

VUE