| Refresh | Home EGTry.com

apply-templates multiple times for the same source


1. one source, apply templates multiple times

2. if no template matchs, apply-tempaltes produce all text contents of all descent children

xml source

<?xml version="1.0" encoding="UTF-8"?>
<root>

  <AA id="a">
    inside A  
    
    <BB id="b"> 
      Inside B 
      <other>More Text</other>
    </BB> 

  </AA>

</root>


xslt stylesheet

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="AA">
    <xsl:apply-templates mode="run1"/>
    <xsl:apply-templates mode="run2"/>
    <xsl:apply-templates />
	</xsl:template>
	
  <xsl:template match="BB" mode="run1">
    <run1>
      name=<xsl:value-of select="name()"/>
      id=<xsl:value-of select="@id"/>
    </run1>
	</xsl:template>

  <xsl:template match="BB" mode="run2">
    <run2>
      name=<xsl:value-of select="name()"/>
      id=<xsl:value-of select="@id"/>
    </run2>
	</xsl:template>


</xsl:stylesheet>


output

<?xml version="1.0" encoding="UTF-8"?>

  
    inside A  
    
    <run1>
      name=BB
      id=b</run1> 

  
    inside A  
    
    <run2>
      name=BB
      id=b</run2> 

  
    inside A  
    
     
      Inside B 
      More Text