collecting with XSLT!

Discussion in 'XML' started by Gunne, Mar 29, 2005.

  1. Gunne

    Gunne Guest

    I have the following xml data available:
    -----------------------------------------------------------------------
    <LinkCategory Name="Hardware" >
    <Link LinkName="hardwarelink1" LinkUrl="www.msn.com"
    PlusLink="False"/>
    <Link LinkName="hardwarelink2" LinkUrl="www.msn.com"
    PlusLink="True"/>
    <Link LinkName="hardwarelink3" LinkUrl="www.msn.com"
    PlusLink="True"/>
    <Link LinkName="hardwarelink4" LinkUrl="www.msn.com"
    PlusLink="False"/>
    <Link LinkName="hardwarelink5" LinkUrl="www.msn.com"
    PlusLink="True"/>
    </LinkCategory>
    <LinkCategory Name="Software" >
    <Link LinkName="Softwarelink1" LinkUrl="www.msn.com"
    PlusLink="False"/>
    <Link LinkName="Softwarelink2" LinkUrl="www.msn.com"
    PlusLink="True"/>
    <Link LinkName="Softwarelink3" LinkUrl="www.msn.com"
    PlusLink="False"/>
    <Link LinkName="Softwarelink4" LinkUrl="www.msn.com"
    PlusLink="False"/>
    <Link LinkName="Softwarelink5" LinkUrl="www.msn.com"
    PlusLink="True"/>
    </LinkCategory>
    -----------------------------------------------------------------------

    And i want to use some kind of Select/test thats collets the links
    with the "PlusLink" set to "True".

    I need the output to look like this:
    -----------------------------------------------------------------------
    David's Plus hardware links:
    hardwarelink2
    hardwarelink3
    hardwarelink5

    Other Hardware links:
    hardwarelink1
    hardwarelink4

    David's Plus software links:
    Softwarelink2
    Softwarelink5

    Other software links:
    Softwarelink1
    Softwarelink3
    Softwarelink4
    -----------------------------------------------------------------------

    Please help me!
     
    Gunne, Mar 29, 2005
    #1
    1. Advertising

  2. Gunne wrote:

    > I have the following xml data available:
    > -----------------------------------------------------------------------
    > <LinkCategory Name="Hardware" >
    > <Link LinkName="hardwarelink1" LinkUrl="www.msn.com"
    > PlusLink="False"/>
    > <Link LinkName="hardwarelink2" LinkUrl="www.msn.com"
    > PlusLink="True"/>
    > <Link LinkName="hardwarelink3" LinkUrl="www.msn.com"
    > PlusLink="True"/>
    > <Link LinkName="hardwarelink4" LinkUrl="www.msn.com"
    > PlusLink="False"/>
    > <Link LinkName="hardwarelink5" LinkUrl="www.msn.com"
    > PlusLink="True"/>
    > </LinkCategory>
    > <LinkCategory Name="Software" >
    > <Link LinkName="Softwarelink1" LinkUrl="www.msn.com"
    > PlusLink="False"/>
    > <Link LinkName="Softwarelink2" LinkUrl="www.msn.com"
    > PlusLink="True"/>
    > <Link LinkName="Softwarelink3" LinkUrl="www.msn.com"
    > PlusLink="False"/>
    > <Link LinkName="Softwarelink4" LinkUrl="www.msn.com"
    > PlusLink="False"/>
    > <Link LinkName="Softwarelink5" LinkUrl="www.msn.com"
    > PlusLink="True"/>
    > </LinkCategory>
    > -----------------------------------------------------------------------
    >
    > And i want to use some kind of Select/test thats collets the links
    > with the "PlusLink" set to "True".
    >
    > I need the output to look like this:
    > -----------------------------------------------------------------------
    > David's Plus hardware links:
    > hardwarelink2
    > hardwarelink3
    > hardwarelink5
    >
    > Other Hardware links:
    > hardwarelink1
    > hardwarelink4
    >
    > David's Plus software links:
    > Softwarelink2
    > Softwarelink5
    >
    > Other software links:
    > Softwarelink1
    > Softwarelink3
    > Softwarelink4


    If you want text output then you need
    <xsl:eek:utput method="text" />
    then it is not difficult to write xsl:for-each loops to output the stuff:

    <?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:template match="/">
    <xsl:text>David's Plus hardware links:
    </xsl:text>
    <xsl:for-each select="Links/LinkCategory[@Name =
    'Hardware']/Link[@PlusLink = 'True']">
    <xsl:value-of select="@LinkName" />
    <xsl:text>
    </xsl:text>
    </xsl:for-each>
    <xsl:text>
    </xsl:text>
    <xsl:text>Other Hardware links:
    </xsl:text>
    <xsl:for-each select="Links/LinkCategory[@Name =
    'Hardware']/Link[@PlusLink != 'True']">
    <xsl:value-of select="@LinkName" />
    <xsl:text>
    </xsl:text>
    </xsl:for-each>
    <xsl:text>
    </xsl:text>
    <xsl:text>David's Plus software links:
    </xsl:text>
    <xsl:for-each select="Links/LinkCategory[@Name =
    'Software']/Link[@PlusLink = 'True']">
    <xsl:value-of select="@LinkName" />
    <xsl:text>
    </xsl:text>
    </xsl:for-each>
    <xsl:text>
    </xsl:text>
    <xsl:text>Other software links:
    </xsl:text>
    <xsl:for-each select="Links/LinkCategory[@Name =
    'Software']/Link[@PlusLink != 'True']">
    <xsl:value-of select="@LinkName" />
    <xsl:text>
    </xsl:text>
    </xsl:for-each>
    </xsl:template>

    </xsl:stylesheet>

    Note that I have assumed there to be a root element named <Links> as the
    parent element of the <LinkCategory> elements.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 29, 2005
    #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. David
    Replies:
    2
    Views:
    319
    Saravana [MVP]
    Jul 12, 2004
  2. Andy

    Collecting data from website ?

    Andy, Aug 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    449
    Curt_C [MVP]
    Aug 5, 2004
  3. =?Utf-8?B?U2lsZWVzaA==?=

    URgent!!! Collecting data from server side

    =?Utf-8?B?U2lsZWVzaA==?=, Nov 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,389
    bruce barker
    Nov 3, 2004
  4. Michael Mitchell via DotNetMonster.com

    Collecting Data on one form and outputing it on another form

    Michael Mitchell via DotNetMonster.com, Jan 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    470
    Michael Mitchell via DotNetMonster.com
    Jan 23, 2005
  5. Replies:
    5
    Views:
    515
    S. Justin Gengo
    Sep 23, 2005
Loading...

Share This Page