This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: xsl unique position
- To: xsl-list at lists dot mulberrytech dot com, mat t <mat at remail dot net>
- Subject: Re: [xsl] xsl unique position
- From: Steven dot C dot Kienle at am dot pnu dot com
- Date: Fri, 9 Mar 2001 08:37:29 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
Mat,
You are getting 1 for the position() each time because Jack and Jill
are both the first Name in the list of Names for each Member. That
is, position is not file dependent, but node-list dependent. Since
you apply-templates for Name under each Member, you end up with a
different node-list each time.
<Group> <!-- position() = 1 -->
<Member> <!-- position() = 1 within /Group/Member -->
<Name>Jack</Name> <!-- position() = 1 within member[1] -->
</Member>
<Member> <!-- position() = 2 within /Group/Member -->
<Name>Jill</Name> <!-- position() = 1 within member[2] -->
</Member>
</Group>
It seems like what you really want is to use the "/Group/Member
position" for identifying the Name. In that case, you can replace the
<xsl:apply-templates select="*"/> in your Member template with the
following
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="Name"/>
</xsl:attribute>
</xsl:element>
<br/>
I am assuming you will have only one Name element under each Member
element here. In that case, you don't really need to call
apply-templates. If you may have more than one Name element under
each Member, you may need to pass the Member position() as a parameter
to the Name template to support uniqueness.
Steve
______________________________ Reply Separator _________________________________
Subject: [xsl] xsl unique position
Author: mat t <mat@remail.net> at Internet-America
Date: 09-03-2001 5:01 AM
Please can you help:
I am losing the variable due to duplication
<Group>
<Member>
<Name>Jack</Name>
</Member>
<Member>
<Name>Jill</Name>
</Member>
</Group>
-----------xsl-------
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="Group/Member"/>
</body>
</html>
</xsl:template>
<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>
The variables sent are -
Member1 =>
Name1 => Jack
Member2
Unfortunately I don't get the second name. I assume that Name1 means
it's position 1 in parent node "Member"
Which means that the second name will also have name1 as it's name and
the form has ignored it thinking it's a duplicate.
Please can you tell me if there is any way to solve this problem.
_____________________________________________________________
Pick up your email anywhere in the world ---> http://www.remail.net
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list