collecting with XSLT!

G

Gunne

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
 
M

Martin Honnen

Gunne said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,840
Latest member
BrendanG78

Latest Threads

Top