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: xsl unique position



> I am losing the variable due to duplication

your example code doesn't use any variables.


<xsl:template match="Member">
 <xsl:apply-templates select="*"/>
 <xsl:element name="input">
  <xsl:attribute name="type">hidden</xsl:attribute>
  <xsl:attribute name="name">Member<xsl:value-of
select="position()"/><xsl:value-of select="position()"/></xsl:attribute>

  <xsl:attribute name="value"></xsl:attribute>
  </xsl:element><br/>
</xsl:template>

<xsl:template match="Name">
Name:
 <xsl:element name="input">
  <xsl:attribute name="type">text</xsl:attribute>
  <xsl:attribute name="name">Name<xsl:value-of
select="position()"/></xsl:attribute>
  <xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>

  </xsl:element><br/>
</xsl:template>

It's hard to see what's happening there as you've written it in the
longest form possible. The above is equivalent to


<xsl:template match="Member">
 <xsl:apply-templates select="*"/>
 <input type="hidden" name="Member{position()}{position()}" value=""/>
 <br/>
</xsl:template>

<xsl:template match="Name">
Name:
  <input type="text" name="Name{position()}" value="{.}"/>
  <xsl:attribute name="type">text</xsl:attribute>
  <br/>
</xsl:template>

there's various things you can use to generate unique names.
you could use name="{generate-id()}" but that may not give you very nice
names or name="Name{count(preceding::Name)}" etc.

David

(Did you mean to duplicate position() in the name of your member input
field ?)


_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

 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]