RE: [xsl] concatenate multiple attribute values and assign it to another attribute

Subject: RE: [xsl] concatenate multiple attribute values and assign it to another attribute
From: "Shaikh, Parvez" <Parvez.Shaikh@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 29 Mar 2007 17:25:55 -0400
based on michael kay response or abels response if I do, the problem is
I
get 4 outputs of testnode
i.e
<testnode att1="1,2,3,4" att2="a,b,c,d" />
<testnode att1="1,2,3,4" att2="a,b,c,d" />
<testnode att1="1,2,3,4"
att2="a,b,c,d" />
<testnode att1="1,2,3,4" att2="a,b,c,d" />

I want it to
output only once.
This is what I have done based on michaels response. The
following is a
portion of the xslt file I have.

 <xsl:template
match="//testnode">
    <testnode>
      <xsl:attribute name="att1">
<xsl:for-each select="//testnode">
          <xsl:value-of select="@att1"/>
<xsl:if test="position()!=last()">,</xsl:if>
        </xsl:for-each>
</xsl:attribute>
      <xsl:attribute name="att2">
        <xsl:for-each
select="//testnode">
          <xsl:value-of select="@att2"/>
<xsl:if test="position()!=last()">,</xsl:if>
        </xsl:for-each>
</xsl:attribute>
    </testnode>
  </xsl:template>


-----Original
Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx] 
Sent: Thursday,
March 29, 2007 5:01 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:
[xsl] concatenate multiple attribute values and assign it
to another
attribute

>  
> I am trying to concat the value of multiple occurence of
an 
> attribute output it as an attribute once.
> 
> <test node att1="1"
att2="a" />
> <test node att1="2" att2="b" />
> <test node att1="3" att2="c"
/>
> <test node att1="4" att2="d" />
>  
> I want to output this as
>
<testnode att1="1,2,3,4" att2="a,b,c,d" />

In XSLT 2.0 (correcting your XML
input)

<testnode>
  <xsl:attribute name="att1" select="testnode/@att1"
separator=","/>
  <xsl:attribute name="att2" select="testnode/@att2"
separator=","/>
</testnode>

In 1.0

<testnode>
  <xsl:attribute
name="att1">
    <xsl:for-each select="testnode">
      <xsl:value-of
select="@att1"/>
      <xsl:if test="position()!=last()">,</xsl:if>
etc.
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--~--
-----------------------------------------
The information contained in this
transmission may be privileged and
confidential and is intended only for the
use of the person(s) named
above. If you are not the intended recipient, or
an employee or agent responsible
for delivering this message to the intended
recipient, any review, dissemination,
distribution or duplication of this
communication is strictly prohibited. If you are
not the intended recipient,
please contact the sender immediately by reply e-mail
and destroy all copies
of the original message. Please note that we do not accept
account orders
and/or instructions by e-mail, and therefore will not be responsible
for
carrying out such orders and/or instructions.  If you, as the intended
recipient
of this message, the purpose of which is to inform and update our
clients, prospects
and consultants of developments relating to our services
and products, would not
like to receive further e-mail correspondence from
the sender, please "reply" to the
sender indicating your wishes.  In the
U.S.: 1345 Avenue of the Americas, New York,
NY 10105.

Current Thread