Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


position() always 1 in for-each

From: "Janette" <jtowell@----------.-------.---.-->
To: NULL
Date: 11/14/2008 1:05:00 PM
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 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent