This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Plse Help! something to do with counter....


Hi, I think I will explain what my project is about to give a better view.

The simplified model is like this:

  Relational Database --> JavaServlet --> XML & XSL -->output

This system is basically an online library system, where a user will query 
the database and convert the result into XML via the servlet.  Then with XSL 
it will be display accordingly.  In the display, only the books that are 
available will have a checkbox assign to it, whereas the others(that are 
being borrowed) will not.

The number of books and the availability of these books are arbitary 
depending on the query result.  The user can borrow more than one books, so 
I need to get the values of each book that the user want to borrow so that I 
can update the database.
(This is the part that I can't get it right)

below is my xml and xsl, Thanks for the help!  (my xsl is very messy, so 
sorry about it..)I use position() in the XSL.

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="trying.xsl"?>
<List xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional";>
<Resource>
<Index>1</Index>
<Type>CD</Type>
<Title>XML and Java</Title>
<Author>Mcgrath</Author>
<Subject>Programming</Subject>
<Serial_no>123-123-123</Serial_no>
<Status>Loan</Status>
<Loaner>loaner</Loaner>
<Date>12/2/2001</Date>
</Resource>
<Resource>
<Index>6</Index>
<Type>Book</Type>
<Title>Java Servlet</Title>
<Author>Suns</Author>
<Subject>Programming</Subject>
<Serial_no>123-123-312</Serial_no>
<Status>Available</Status>
<Loaner>nil</Loaner>
<Date>nil</Date>
</Resource>
<Resource>
<Index>8</Index>
<Type>Book</Type>
<Title>Java XML Programming</Title>
<Author>Wrox</Author>
<Subject>XML Programming</Subject>
<Serial_no>1233-2390</Serial_no>
<Status>Available</Status>
<Loaner>nil</Loaner>
<Date>nil</Date>
</Resource>
<Resource>
<Index>9</Index>
<Type>CD</Type>
<Title>Java Programming</Title>
<Author>Suns</Author>
<Subject>Programming</Subject>
<Serial_no>1239-12391</Serial_no>
<Status>Available</Status>
<Loaner>nil</Loaner>
<Date>nil</Date>
</Resource>
<Resource>
<Index>10</Index>
<Type>CD</Type>
<Title>Java 2EE</Title>
<Author>Suns</Author>
<Subject>Programming</Subject>
<Serial_no>1239-12390</Serial_no>
<Status>Available</Status>
<Loaner>nil</Loaner>
<Date>nil</Date>
</Resource>
</List>

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

<xsl:template match="/">
<html><body>
<form method="GET" action="../servlet/takeLoan">
<xsl:for-each select="List/Resource">
<table width="100%"><xsl:variable name="num"><xsl:number 
count="Resource"/></xsl:variable><span><xsl:value-of select="$num"/></span>
<tr><td width="25%">Title :&#160;<xsl:value-of select="Title"/></td>

<td width="25%">Author :&#160;<xsl:value-of select="Author"/></td></tr>
</table>
<xsl:variable name="stat"><xsl:value-of select="Status"/></xsl:variable>
<xsl:choose>
<xsl:when test="$stat='Available'">
<div align="right"><input type="checkbox" name="c{position()}" 
value="{Index}"/><span>to Loan</span></div><br/>
</xsl:when>
<xsl:otherwise>
<table width="100%"><tr><td width="25%">Loaner :&#160;<xsl:value-of 
select="Loaner"/></td>
<td width="25%">Date of Loan :&#160;<xsl:value-of select="Date"/></td>
</tr></table><br/>
</xsl:otherwise>
</xsl:choose>

<hr/>
</xsl:for-each>
<input type="submit" name="submit" value="Loan"/>
</form>
</body></html>
</xsl:template>
</xsl:stylesheet>

>From: Jeni Tennison <mail@jenitennison.com>
>Reply-To: Jeni Tennison <mail@jenitennison.com>
>To: "Poh Justin KT" <nitsujpoh@hotmail.com>
>CC: xsl-list@lists.mulberrytech.com
>Subject: Re: [xsl] Plse Help! something to do with counter....
>Date: Wed, 2 May 2001 11:12:10 +0100
>
>Hi Justin,
>
> > Hi, Thanks! It instead solve much of my problems but if I want to
> > omit any one of the Resource element, for e.g I don't want to have a
> > checkbox for the 3rd element but I still want to display other
> > values of this element, and at the same time the value attribute of
> > the checkbox will still be in consecutive numbers. position() don't
> > seem to be able to work this way...
>
>If you want to omit a Resource element, then don't select it with the
>xsl:apply-templates.  So for example, if you don't want to get a
>checkbox for the third Resource element, then use:
>
>   <xsl:apply-templates select="List/Resource[position() != 3]" />
>
>If you want to select the Resource elements that have a type attribute
>equal to 'checkbox' then use:
>
>   <xsl:apply-templates select="List/Resource[@type = 'checkbox']" />
>
>The nodes that you select are the nodes that make up the current node
>list, and the ones against which the position of the particular
>Resource element you're processing will be judged.
>
>If there are more technical details about which Resource elements
>should be turned into checkboxes and which not, or about the output
>that you want, then you should post them.  We don't mind complicated
>XML, but the XSLT that's appropriate might change quite radically
>depending on the technical details of your problem, so if the above
>isn't appropriate, then do give us a sample of your source and what
>you want as output.
>
>I hope that helps anyway,
>
>Jeni
>
>---
>Jeni Tennison
>http://www.jenitennison.com/
>
>

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]