Showing node-level members of a global set

Discussion in 'XML' started by ion, Jun 2, 2006.

  1. ion

    ion Guest

    Hi! I'm struggling with doing this in an elegant way -- I'll get my
    XSLT books out of storage this weekend, but for now I could use some
    help.
    <bedknob>
    <broomstick>
    <bippity>boppity</bippity>
    </broomstick>
    <broomstick>
    <bippity>boppity</bippity>
    <bippity>boo</bippity>
    </broomstick>
    </bedknob>
    I'd like to get the complete list of bippities, then compare the
    bippities of each broomstick to them, and make a mark for each present
    member of the complete set of bippities in a particular broomstick,
    like
    <table>
    <thead>
    <tr>
    <th>boppity
    </th>
    <th>boo
    </th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>X
    </td>
    <td>
    </td>
    </tr>
    <tr>
    <td>X
    </td>
    <td>X
    </td>
    </tr>
    </tbody>
    </table>

    OK. So, I use a Muenchian sort to get the unique list of bippities for
    the thead element, but then to do the rows in the body, I have to go
    through it again, and check each member against the set of present
    values. I'm thinking of something like taking the intersection and
    looking for count() = 2, but I'm having trouble making it happen.

    Can you help me?

    Ion
    ion, Jun 2, 2006
    #1
    1. Advertising

  2. ion

    Joris Gillis Guest

    Hi,

    On Fri, 02 Jun 2006 21:54:32 +0200, ion <> wrote:

    > Hi! I'm struggling with doing this in an elegant wayI'd like to get the
    > complete list of bippities, then compare the
    > bippities of each broomstick to them, and make a mark for each present
    > member of the complete set of bippities in a particular broomstick,
    > like



    I have no idea if this will conform to your idea of elegance (it uses
    plain dumb for-each loops), but this solution seems to work:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml" indent="yes"/>

    <xsl:key name="b" match="bippity" use="."/>
    <xsl:variable name="bip"
    select="//*[generate-id()=generate-id(key('b',.)[1])]"/>

    <xsl:template match="bedknob">
    <table>
    <thead>
    <tr>
    <xsl:for-each select="$bip">
    <th><xsl:value-of select="."/></th>
    </xsl:for-each>
    </tr>
    </thead>
    <tbody>
    <xsl:apply-templates select="broomstick"/>
    </tbody>
    </table>
    </xsl:template>

    <xsl:template match="broomstick">
    <xsl:variable name="this" select="bippity"/>
    <tr>
    <xsl:for-each select="$bip">
    <td>
    <xsl:if test=".=$this">X</xsl:if>
    </td>
    </xsl:for-each>
    </tr>
    </xsl:template>

    </xsl:stylesheet>


    regards,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Veni, vidi, wiki (http://www.wikipedia.org)
    Joris Gillis, Jun 3, 2006
    #2
    1. Advertising

  3. ion

    ion Guest

    Thanks, Joris, that works great.
    Ion

    Joris Gillis wrote:
    > Hi,
    >
    > On Fri, 02 Jun 2006 21:54:32 +0200, ion <> wrote:
    >
    > > Hi! I'm struggling with doing this in an elegant wayI'd like to get the
    > > complete list of bippities, then compare the
    > > bippities of each broomstick to them, and make a mark for each present
    > > member of the complete set of bippities in a particular broomstick,
    > > like

    >
    >
    > I have no idea if this will conform to your idea of elegance (it uses
    > plain dumb for-each loops), but this solution seems to work:
    >
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="xml" indent="yes"/>
    >
    > <xsl:key name="b" match="bippity" use="."/>
    > <xsl:variable name="bip"
    > select="//*[generate-id()=generate-id(key('b',.)[1])]"/>
    >
    > <xsl:template match="bedknob">
    > <table>
    > <thead>
    > <tr>
    > <xsl:for-each select="$bip">
    > <th><xsl:value-of select="."/></th>
    > </xsl:for-each>
    > </tr>
    > </thead>
    > <tbody>
    > <xsl:apply-templates select="broomstick"/>
    > </tbody>
    > </table>
    > </xsl:template>
    >
    > <xsl:template match="broomstick">
    > <xsl:variable name="this" select="bippity"/>
    > <tr>
    > <xsl:for-each select="$bip">
    > <td>
    > <xsl:if test=".=$this">X</xsl:if>
    > </td>
    > </xsl:for-each>
    > </tr>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
    >
    > regards,
    > --
    > Joris Gillis (http://users.telenet.be/root-jg/me.html)
    > Veni, vidi, wiki (http://www.wikipedia.org)
    ion, Jun 5, 2006
    #3
    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:
    1,375
  2. Alan Silver
    Replies:
    0
    Views:
    508
    Alan Silver
    Dec 21, 2005
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,392
    Dimitre Novatchev
    Aug 24, 2006
  4. Replies:
    0
    Views:
    507
  5. pabbu
    Replies:
    8
    Views:
    700
    Marc Boyer
    Nov 7, 2005
Loading...

Share This Page