Learn XML, XSLT, XPath with Tutorials & Samples


xsl:param
XML XSL

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="myFile.xslt"?>

<store>

  <book id="1">
    <title>XML</title>
    <author>Bill</author>
    <price>25.50</price>
  </book>

  <book id="2">
    <title>XSL</title>
    <author>Vijay</author>
    <price>75.60</price>
  </book>

  <book id="3">
    <title>HTML</title>
    <author>Kris</author>
    <price>50.40</price>
  </book>

</store>

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

  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr>
            <th>Title</th>
            <th>Price</th>
          </tr>
          <xsl:for-each select="store/book">
            <xsl:call-template name ="getBookDetails">
              <xsl:with-param  name ="pTitle" select ="title"/>
              <xsl:with-param  name ="pPrice" select ="price"/>
            </xsl:call-template>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template name ="getBookDetails">
    <xsl:param name ="pTitle"/>
    <xsl:param name ="pPrice"/>

    <xsl:if test="price &gt;= 30">
      <tr>
        <td><xsl:value-of select="$pTitle"/></td>
        <td><xsl:value-of select="$pPrice"/></td>
      </tr>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>


OutPut:

Title Price
XSL 75.60
HTML 50.40