this code is not showing any result for me please help......

Please help... this code is not showing any result........
bookstylesheet.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/collection">
<b> <xsl:text>* bookk details sortedin descending order of their pric*</xsl:text></b>

<xsl:for-each select="bookinfo/book">
<xsl:sort select="price" data-type="number" order="descending"/>
<hr>
<xsl:value-of select="@bookid"/> </br>
<xsl:value-of select="bookname"/> </br>
<font color="red"><xsl:apply-templates select="price"/></font><br/>
</hr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

book.xml

<?xml version="1.0" ?>
<?xml-stylesheet href="C:\Users\ajasawant\Downloads\AIT PRoject\xml practice\bookstylesheet.xsl" type="text/xsl" ?>
<bookinfo>
<book bookid="B001" category="practical">
<bookname>php and xml</bookname>
<authorname>neelima padmawar</authorname>
<price>120</price>
</book>
<book bookid="B002" category="practical">
<bookname>java</bookname>
<authorname>alok pawar</authorname>
<price>140</price>
</book>
</bookinfo>
Ajay SawantStudentAsked:
Who is Participating?
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <b> <xsl:text>* bookk details sortedin descending order of their pric*</xsl:text></b>
        
        <xsl:for-each select="bookinfo/book">
            <xsl:sort select="price" data-type="number" order="descending"/>
            <hr/>
                <xsl:value-of select="@bookid"/> <br/>
                <xsl:value-of select="bookname"/> <br/>
                <font color="red"><xsl:apply-templates select="price"/></font><br/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
first you had the root wrong, your root element is not collection, so I changed the match attribute to a "/"
after that I tweaked the hr and br to be wellformed
1
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
I recommend however that you avoid for-each for accessing child nodes the way you do
That is a pretty procedural way of programming XSLT that will be hard to maintain if things get more complex
Please learn right from the start to use the more functional mechanism of apply templates

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:template match="/">
        <b>
            <xsl:text>* bookk details sortedin descending order of their pric*</xsl:text>
        </b>
        
        <xsl:apply-templates select="bookinfo/book">
            <xsl:sort select="price" data-type="number" order="descending"/>
        </xsl:apply-templates>
        
    </xsl:template>
    
    <xsl:template match="book">
        <hr/>
        <xsl:value-of select="@bookid"/> <br/>
        <xsl:value-of select="bookname"/> <br/>
        <font color="red"><xsl:apply-templates select="price"/></font><br/>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
answered to the full
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.