| Refresh | Home EGTry.com

xslt scan source templates


1. the order of templates in the stylesheet is not significant.

2. the order in the source is

scan peudocode

 for each element in the source code {
    find a best fit template to the element
    if (found) { 
      apply the template to the element
    } else {
      next
    }
 }


xml

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

  <AA id="aa1"> AA1 </AA>
  <AA id="aa2"> AA2 </AA>
  <AA id="aa3"> AA3 </AA>

  <BB id="bb1"> BB1 </BB>
  <BB id="bb2"> BB2 </BB>
  <BB id="bb3"> BB3 </BB>

  <AA id="aa4"> AA4 </AA>
  <AA id="aa5"> AA5 </AA>

</root>


stylesheet

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

  <xsl:template match="AA">
    <a>
      <xsl:value-of select="name()"/>
      <xsl:value-of select="@id"/>
    </a>
	</xsl:template>
	
  <xsl:template match="BB">
    <b>
      name=<xsl:value-of select="name()"/>
      id=<xsl:value-of select="@id"/>
    </b>
	</xsl:template>

</xsl:stylesheet>


output

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

  <a>AAaa1</a>
  <a>AAaa2</a>
  <a>AAaa3</a>

  <b>
      name=BB
      id=bb1</b>
  <b>
      name=BB
      id=bb2</b>
  <b>
      name=BB
      id=bb3</b>

  <a>AAaa4</a>
  <a>AAaa5</a>