Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > collecting with XSLT!

Reply
Thread Tools

collecting with XSLT!

 
 
Gunne
Guest
Posts: n/a
 
      03-29-2005
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!
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-29-2005


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
<xslutput 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
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xslutput 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collecting mail from one pop account onto two computers in TB Waltzzz Firefox 1 02-14-2005 06:07 PM
Collecting data from website ? Andy ASP .Net 1 08-05-2004 01:28 PM
Switch for collecting traffic ramialhasan Cisco 0 07-22-2004 07:27 AM
collecting html control IDs on a form David ASP .Net 2 07-12-2004 03:46 AM
Tools for collecting IP source and destination (subnet) pair statistics ? Keith B. Cisco 4 01-30-2004 07:16 PM



Advertisments