freelanceprogrammers.org Forum Index » XML / XSL

XSLT Data Filtering


View user's profile Post To page top
gregfeiereisel Posted: Tue Jul 12, 2005 2:12 am


Joined: 12 Jul 2005

Posts: 1
XSLT Data Filtering
Hello,

I am new to XML/XSL and I have a quick question. I have a set of
data in xml format and a stylesheet to transform it to a readable
format. The way the data is set up is like this.

<Content1>
<Content2>
<Content1>
<Content2>
<Content1>
<Content2>
<Content1>
<Content2>

etc.

In some cases the content1 is exactly the same as the previous value
for content1. What I would like to do is have the stylesheet not
display the value of content1 if it is the same as the previous. I
have done this before using IF statements and variables in ASP but I
cannot see how this can be done in XML/XSLT. I am told that in XSL
the values for variables cannot change so I am stuck...

Please help!

Thanks,
Greg
Reply with quote
Send private message
View user's profile Post To page top
rweinheimer Posted: Tue Jul 12, 2005 5:20 am


Joined: 02 May 2005

Posts: 10
XSLT Data Filtering
This might be an oversimplification. It only filters
if the previous (literally) item is the same. If what
you really want to do is filter all duplicates, that
might be more complicated, but fwiw...

[test.xml]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<contents>
<Content1>
<Content2>2</Content2>
</Content1>
<Content1>
<Content2>2</Content2>
</Content1>
<Content1>
<Content2>3</Content2>
</Content1>
<Content1>
<Content2>4</Content2>
</Content1>
</contents>


[test.xslt]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="//Content1">
<xsl:variable name="this"><xsl:value-of
select="."/></xsl:variable>
<xsl:choose>
<xsl:when test="preceding-sibling::Content1 =
$this"></xsl:when>
<xsl:otherwise>
<p><xsl:value-of select="."/></p>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

--- gregfeiereisel <gfeiereisel@...> wrote:

> Hello,
>
> I am new to XML/XSL and I have a quick question. I
> have a set of
> data in xml format and a stylesheet to transform it
> to a readable
> format. The way the data is set up is like this.
>
> <Content1>
> <Content2>
> <Content1>
> <Content2>
> <Content1>
> <Content2>
> <Content1>
> <Content2>
>
> etc.
>
> In some cases the content1 is exactly the same as
> the previous value
> for content1. What I would like to do is have the
> stylesheet not
> display the value of content1 if it is the same as
> the previous. I
> have done this before using IF statements and
> variables in ASP but I
> cannot see how this can be done in XML/XSLT. I am
> told that in XSL
> the values for variables cannot change so I am
> stuck...
>
> Please help!
>
> Thanks,
> Greg
>
>
>
>
>
> Yahoo! Groups Links
>
>
> xml-doc-unsubscribe@yahoogroups.com
>
>
>
>
>




____________________________________________________
Sell on Yahoo! Auctions – no fees. Bid on great items.
http://auctions.yahoo.com/
Reply with quote
Send private message
View user's profile Post To page top
chris.bowering@... Posted: Tue Jul 12, 2005 3:59 pm


Joined: 12 Jul 2005

Posts: 1
XSLT Data Filtering
The best technique I`ve found to do this is the Muenchian Method:

http://www.jenitennison.com/xslt/grouping/muenchian.html



-----Original Message-----
From: xml-doc@yahoogroups.com [mailto:xml-doc@yahoogroups.com] On Behalf
Of gregfeiereisel
Sent: Monday, July 11, 2005 5:13 PM
To: xml-doc@yahoogroups.com
Subject: [xml-doc] XSLT Data Filtering

Hello,

I am new to XML/XSL and I have a quick question. I have a set of data
in xml format and a stylesheet to transform it to a readable format.
The way the data is set up is like this.

<Content1>
<Content2>
<Content1>
<Content2>
<Content1>
<Content2>
<Content1>
<Content2>

etc.

In some cases the content1 is exactly the same as the previous value for
content1. What I would like to do is have the stylesheet not display
the value of content1 if it is the same as the previous. I have done
this before using IF statements and variables in ASP but I cannot see
how this can be done in XML/XSLT. I am told that in XSL the values for
variables cannot change so I am stuck...

Please help!

Thanks,
Greg





Yahoo! Groups Links




This message may contain privileged and/or confidential information. If
you have received this e-mail in error or are not the intended recipient, you
may not use, copy, disseminate or distribute it; do not open any attachments,
delete it immediately from your system and notify the sender promptly by e-mail
that you have done so. Thank you.
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help