English 中文(简体)
XSLT - <apply-template>
  • 时间:2024-12-22

XSLT <apply-template>


Previous Page Next Page  

和带;xsl:apply-template> 标记信号是SLT处理器根据每一选定噪音的类型和背景找到适当的模板。

Declaration

以下是<xsl:apply-template>。 内容。

<xsl:apply-template 
   select = Expression 
   mode = QName > 
</xsl:apply-template> 

Attributes

Sr.No Name & Description
1

用于处理XPath表达方式选择的节点,而不是处理所有的儿童。

2

允许按其资格分类的某一要素进行多次处理,每次都产生不同的结果。

Elements

Number of occurrences Unpmited

xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:foreach, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processinstruction, xsl:template, xsl:xxiable, xsl: when, xsl:with-param

xsl:sort, xsl:with-param

Demo Example

举例来说,该表列出了“和”;其属性如下:rollno及其子女及子女;第一名称与“;最后名称与”;“和”;“和”;“nick”;“和”;“mark”;和“lt”;“mark”;“mark”;“mark”;“mark”;“mark”;“mark”;“mark”;“ by”;”;对每个学生进行 it。

students.xml

<?xml version = "1.0"?> 
<?xml-stylesheet type = "text/xsl" href = "students.xsl"?> 
<class> 
   <student rollno = "393"> 
      <firstname>Dinkar</firstname> 
      <lastname>Kad</lastname> 
      <nickname>Dinkar</nickname> 
      <marks>85</marks> 
   </student> 
   <student rollno = "493"> 
      <firstname>Vaneet</firstname> 
      <lastname>Gupta</lastname> 
      <nickname>Vinni</nickname> 
      <marks>95</marks> 
   </student> 
   <student rollno = "593"> 
      <firstname>Jasvir</firstname> 
      <lastname>Singh</lastname> 
      <nickname>Jazz</nickname> 
      <marks>90</marks> 
   </student> 
</class>

students.xsl

<?xml version = "1.0" encoding = "UTF-8"?> 
<xsl:stylesheet version = "1.0" 
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">   
   <xsl:template match = "/"> 
      <html> 
         <body> 
            <h2>Students</h2> 
            <xsl:apply-templates select = "class/student" /> 
         </body> 
      </html> 
   </xsl:template>  

   <xsl:template match = "class/student"> 
      <xsl:apply-templates select = "@rollno" /> 
      <xsl:apply-templates select = "firstname" /> 
      <xsl:apply-templates select = "lastname" /> 
      <xsl:apply-templates select = "nickname" /> 
      <xsl:apply-templates select = "marks" /> 
      <br /> 
   </xsl:template>  

   <xsl:template match = "@rollno"> 
      <span style = "font-size = 22px;"> 
         <xsl:value-of select = "." /> 
      </span> 
      <br /> 
   </xsl:template>  

   <xsl:template match = "firstname"> 
      First Name:<span style = "color:blue;"> 
         <xsl:value-of select = "." /> 
      </span> 
      <br /> 
   </xsl:template>  

   <xsl:template match = "lastname"> 
      Last Name:<span style = "color:green;"> 
         <xsl:value-of select = "." /> 
      </span> 
      <br /> 
   </xsl:template>  

   <xsl:template match = "nickname"> 
      Nick Name:<span style = "color:red;"> 
         <xsl:value-of select = "." /> 
      </span> 
      <br /> 
   </xsl:template>  

   <xsl:template match = "marks"> 
      Marks:<span style = "color:gray;"> 
         <xsl:value-of select = "." /> 
      </span> 
      <br /> 
   </xsl:template>  
	
</xsl:stylesheet>

Output

Formatted Apply Template Output Advertisements