XML:Creating XML Document Using XSL (For-Each)

Friday 24 February 2012
Step 1:
First Create XML File And Name It As Fourth.XML
<?xml version="1.0" encoding="utf-8"?>
<?xml:stylesheet type="text/xsl" href="Fourth.xsl"?>
<PRODUCTDATA>
    <PRODUCT PRODID="P001"  CATEGORY="TOY">
        <PRODUCTNAME>Mini Bus</PRODUCTNAME>
        <DESCRIPTION>This is a toy for children aged 4 and above</DESCRIPTION>
        <PRICE>75</PRICE>
        <QUANTITY>54</QUANTITY>
    </PRODUCT>

    <PRODUCT PRODID="P002"  CATEGORY="TOY">
        <PRODUCTNAME>Barbie Doll</PRODUCTNAME>
        <Description>This is a toy for children age group of 5-10</Description>
        <Price>20</Price>
        <Quantity>200</Quantity>
    </PRODUCT>
   
</PRODUCTDATA>



Step 2:
Then Create CSS File And Name It As Fourth.xsl
<?xml version="1.0" encoding="utf-8"?>

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

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

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

<xsl:template match="/">
    <xsl:for-each select="PRODUCTDATA/PRODUCT">
        <xsl:sort select="PRODUCTNAME" data-type="text" order="ascending"/>
    PRODUCT NAME:<xsl:value-of select="PRODUCTNAME"/><BR/>
    DESCRIPTION:<xsl:value-of select="DESCRIPTION"/><BR/>
    PRICE:<xsl:value-of select="PRICE"/><BR/>
    QUANTITY:<xsl:value-of select="QUANTITY"/><BR/>
    <html>
    <body>
    <!--
        This is an XSLT template file. Fill in this area with the
        XSL elements which will transform your XML to XHTML.
    -->
    </body>
    </html>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>






0 comments:

Post a Comment