removing/combining doubles in xml

Discussion in 'XML' started by lievemario, Nov 29, 2004.

  1. lievemario

    lievemario Guest

    Hey,

    I have generated following xml file (using perl,dbi),

    Now I would like to display this with the help of xsl

    such that I have the following result:

    A B (XXXX) (YYYY)

    Can someone help me with that?

    Thanks

    Here is the xml file

    <List_personnel>

    <select>

    <Personnel_member>

    <person_id>224</person_id>

    <name>A</name>

    <first_name>B</first_name>

    <team_code>XXXX</team_code>

    </Personnel_member>

    <Personnel_member>

    <person_id>224</person_id>

    <name>A</name>

    <first_name>B</first_name>

    <team_code>YYYY</team_code>

    </Personnel_member>

    </select>

    </List_personnel>
    lievemario, Nov 29, 2004
    #1
    1. Advertising

  2. lievemario

    Joris Gillis Guest

    > I have generated following xml file (using perl,dbi),
    >
    > Now I would like to display this with the help of xsl
    >
    > such that I have the following result:
    >
    > A B (XXXX) (YYYY)
    >
    > Can someone help me with that?


    Hi,
    In XSLT 1.0, there is no standard way to do that task, but you can use e.g. generate-id() in combination with key() , to obtain a result. Another way is to use extension functions.
    This is a possible solution:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:eek:utput method="text"/>

    <xsl:key name="p_id" match="Personnel_member" use="person_id"/>

    <xsl:template match="select">
    <xsl:for-each select="Personnel_member[ generate-id(.) = generate-id(key('p_id',person_id))]">
    <xsl:apply-templates select="name"/>
    <xsl:apply-templates select="first_name"/>
    <xsl:apply-templates select="../Personnel_member[person_id=current()/person_id]/team_code"/>
    </xsl:for-each>
    </xsl:template>

    <xsl:template match="team_code">
    (<xsl:value-of select="."/>)
    </xsl:template>

    </xsl:stylesheet>



    regards,

    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Nov 29, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    499
  2. BaKMaN
    Replies:
    0
    Views:
    371
    BaKMaN
    Jan 30, 2004
  3. johdah
    Replies:
    0
    Views:
    355
    johdah
    Mar 4, 2004
  4. dan
    Replies:
    1
    Views:
    2,302
    Jack Klein
    Nov 26, 2003
  5. Chris  Chiasson
    Replies:
    6
    Views:
    604
    Richard Tobin
    Nov 14, 2006
Loading...

Share This Page