Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - position() always 1 in for-each >Thread Next - Re: position() always 1 in for-each Re: position() always 1 in for-eachTo: NULL Date: 11/14/2008 1:36:00 PM It took a lunch break for me to realise, that I was calling the code that built the xml multiple times, and therefore it never had more than one user node per call. Instead now I save up the resulting xml till the end and then call transform and it correctly increments position(). Sorry for the wasted post. Janette "Janette" <jtowell@r...> wrote in message news:ehyz31fRJHA.1164@T...... > Hi, > > Firstly I apologise in advance I only just started using xsl yesterday. Am > I am a beginner with XML. I have tried to find the answer to my problem on > the web but just can't. > > I want to output as a table all user nodes. Including a radio button > collection with distinct names for each row. I have tried to use > position() as I understood that this gives the position of the node that > is being processed, but it always comes back as 1. I am guessing that my > problem is something to do with the template match and for each > combination but I can't work it out. > > ie I want as output > <tr><td>1234</td><td>Joe Smith</td><td><input type="radio" > checked="checked" name="1" /></td><td><input type="radio" > name="1"/></td></tr> > <tr><td>5678</td><td>Jane Brown</td><td><input type="radio" name="2" > /></td><td><input type="radio" checked="checked" name="2"/></td></tr> > > but instead I get as output > <tr><td>1234</td><td>Joe Smith</td><td><input type="radio" > checked="checked" name="1" /></td><td><input type="radio" > name="1"/></td></tr> > <tr><td>5678</td><td>Jane Brown</td><td><input type="radio" name="1" > /></td><td><input type="radio" checked="checked" name="1"/></td></tr> > > XML file looks like this > > <root> > <user> > <account>1234</account> > <name>Joe Smith</name> > <neverexp>True</neverexp> > </user> > <root> > <user> > <account>5678</account> > <name>Jane Brown</name> > <neverexp>False</neverexp> > </user> > </root> > > xsl file looks like this > <?xml version="1.0" encoding="ISO-8859-1"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:template match="/"> > <xsl:for-each select="root/user"> > <tr> > <td><xsl:value-of select="account" /></td> > <td><xsl:value-of select="name"/></td> > <xsl:choose> > <xsl:when test="neverexp='True'"> > <td align="center"> > <input type="radio" checked="checked"> > <xsl:attribute name="name"><xsl:value-of > select="position()"/></xsl:attribute> > </input> > </td> > <td align="center"> > <input type="radio"> > <xsl:attribute name="name"><xsl:value-of > select="position()"/></xsl:attribute> > </input> > </td> > </xsl:when> > <xsl:otherwise> > <td align="center"> > <input type="radio"> > <xsl:attribute name="name"><xsl:value-of > select="position()"/></xsl:attribute> > </input> > </td> > <td align="center"> > <input type="radio" checked="checked"> > <xsl:attribute name="name"><xsl:value-of > select="position()"/></xsl:attribute> > </input> > </td> > </xsl:otherwise> > </xsl:choose> > </tr> > </xsl:for-each> > </xsl:template> > </xsl:stylesheet> > > Thanks in advance for your assistance. > Janette > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
