[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Counting elements with count() and position()
Hi, I'm using trying to use the function's position() and count() to help format some HTML output. The position() function is working well for me however I think I'm positioning the count() function incorectly. This what I started with: <tr><td>url:</td><td>www.footyworld.com</td></tr> <tr><td>url:</td><td>www.footyworld.com.au</td></tr> I've used position() to take the next formating step: <tr><td>url:</td><td>www.footyworld.com</td></tr> <tr><td></td><td>www.footyworld.com.au</td></tr> Now I what to use count() to add a plural 's' to my formatting so it's like: <tr><td>urls:</td><td>www.footyworld.com</td></tr> <tr><td></td><td>www.footyworld.com.au</td></tr> This last formating step throws an error. I'm setting an xsl variable, $addresscount, straight after an <xsl:for-each> tag and trying to use the value in an <xsl:template> tag. My thinking is the $addresscount var. is reset each <website> node. Can you help correct me with this? Below is a trimmed down version of the xml and xsl files. As I've trimmed it down in this email I have checked for typo's and I trust their are none. I've been trying different positions with these tags without joy so I though I'd ask. Many thanks Cheers Rudi. XML file: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/XML/XLink/0.9"> <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="webapps2.xsl"?> <webapps xmlns:xlink="http://www.w3.org/XML/XLink/0.9"> <website name="Footyworld"> <address xlink:type="simple" xlink:href="http://www.footyworld.com">www.footyworld.com</address> <address xlink:type="simple" xlink:href="http://www.footyworld.com.au">www.footyworld.com.au</address> </website> </webapps> XSL file: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/XML/XLink/0.9"> <xsl:template match="/"> <html> <head><title>Web app. list</title></head> <body> <xsl:for-each select="webapps/website"> <xsl:variable name="addresscount" select="count(address)"/> <table border="1"> <xsl:apply-templates select="address"/> </table> </xsl:for-each> </body> </html> </xsl:template> <xsl:template match="address"> <tr> <xsl:choose> <xsl:when test="position() = 1"> <td class="title"> <xsl:choose> <xsl:when test="$addresscount > 1">urls:</xsl:when> <xsl:otherwise>url:</xsl:otherwise> </xsl:choose> </td> </xsl:when> <xsl:otherwise> <td></td> </xsl:otherwise> </xsl:choose> <td><a href="{@xlink:href}"><xsl:value-of select="."/></a></td> </tr> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|