Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2007, 06:29 AM
Registered User
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml&xslt

hi, can anyone help me out

this is my problem..
i want to retrieve data from XML using XSLT..
and when user gives the input in textbox(for example grouping)
it must give the result....



this is my xml format...

<?xml version="1.0" encoding="utf-8" ?>
<bank>
    <customername>
        <branchid>V667320</branchid>
        <name>ram</name>
        <balance>1000</balance>
        <quantity>178</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>M382932</branchid>
        <name>sam</name>
        <balance>2000</balance>
        <quantity>129</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>U3923839</branchid>
        <name>raj</name>
        <balance>3000</balance>
        <quantity>200</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>Q3929302</branchid>
        <name>rakesh</name>
        <balance>4000</balance>
        <quantity>623</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>L930389</branchid>
        <name>mani</name>
        <balance>5000</balance>
        <quantity>45</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>P9392393</branchid>
        <name>suresh</name>
        <balance>20000</balance>
        <quantity>3,230</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>P8228829</branchid>
        <name>vinoth</name>
        <balance>2000</balance>
        <quantity>129</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>Y7829232</branchid>
        <name>nanda</name>
        <balance>4555</balance>
        <quantity>299</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>M7382393</branchid>
        <name>krishna</name>
        <balance>26556</balance>
        <quantity>1,198</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>L2329303</branchid>
        <name>mugun</name>
        <balance>6263</balance>
        <quantity>2,450</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>E2930230</branchid>
        <name>viki</name>
        <balance>6526</balance>
        <quantity>299</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>I3029320</branchid>
        <name>bala</name>
        <balance>4844</balance>
        <quantity>3,450</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>V123049</branchid>
        <name>mala</name>
        <balance>2458</balance>
        <quantity>1,030</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>C039890</branchid>
        <name>ganesh</name>
        <balance>45454</balance>
        <quantity>1,430</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>M392829</branchid>
        <name>mahesh</name>
        <balance>4544</balance>
        <quantity>129</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>D190315</branchid>
        <name>hari</name>
        <balance>2112</balance>
        <quantity>45</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>E938393</branchid>
        <name>ajesh</name>
        <balance>1232</balance>
        <quantity>230</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>V392839</branchid>
        <name>ashkott</name>
        <balance>23233</balance>
        <quantity>95</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>K928379</branchid>
        <name>balaji</name>
        <balance>3213</balance>
        <quantity>329</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>I303920</branchid>
        <name>kumar</name>
        <balance>31154</balance>
        <quantity>698</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>V123049</branchid>
        <name>muaran</name>
        <balance>4484</balance>
        <quantity>30</quantity>
        <location>adyar</location>
    </customername>
    <customername>
        <branchid>V392039</branchid>
        <name>vignesh</name>
        <balance>4848</balance>
        <quantity>335</quantity>
        <location>tnagar</location>
    </customername>
    <customername>
        <branchid>L930389</branchid>
        <name>kishore</name>
        <balance>8551</balance>
        <quantity>30</quantity>
        <location>adyar</location>
    </customername>
</bank>



my XSLT is below


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

  <xsl:key name="bank" match="customername" use="location" />

 <xsl:template match="/">
  <xsl:apply-templates />
  </xsl:template>

 <xsl:template match="bank">
  <xsl:call-template name="Style" />
  <h1>Grouping of bank by location</h1>

 <xsl:for-each select="//customername[generate-id(.)=generate-id(key('bank',location))]">

  <xsl:sort select="name" order="ascending" />

 <h3>
  <xsl:value-of select="location" />
  location
  </h3>

 <table border="1">
 <tr>
  <th>customername Name</th>
  <th>balance</th>
  <th>location</th>
  </tr>

 <xsl:for-each select="key('bank',location)">

  <xsl:sort select="name" />
 <tr>
 <td>
  <xsl:value-of select="name" />
  </td>
<td>
  <xsl:value-of select="balance" />
  </td>
<td>
  <xsl:value-of select="location" />
  </td>
  </tr>
  </xsl:for-each>
  </table>
  <br />
  <br />
  </xsl:for-each>
</xsl:stylesheet>
  </xsl:template>
</xsl:stylesheet>



my program is right.. but i dnt want to hardcode it........

i mean when i give the input in textbox and when i press search button.. it must list the corresponding details...........

please help me out... or do u hve any sample programs of this kind...



 
Old September 20th, 2007, 08:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You haven't made it clear exactly what the user is entering in the text box. If it's an element name, you can replace

customername

by

*[name()=$param]

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 20th, 2007, 10:30 AM
Registered User
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

iv l tell u clearly....
if i want to group tht items in location wise....
i must enter the needed location in text box.. when i press show button... it must display all the records which exists in tht location.........( for xample location - adyar)...
hope u people can help me out






Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript & XML & NN lmod Javascript How-To 0 August 18th, 2005 03:16 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
XML from a DB recordset (removal of &lt;&gt;) Thodoris XML 3 July 13th, 2004 12:28 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.