XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Posttop
Viral GuptaSubject: problems with grouping in xslt
Author: Viral Gupta
Date: 14 Mar 2007 10:01 AM
Hi,

someone pls help me on this.

following is my xml...

I need to take out papers for each type separately.
and then this each type should have area seperately.

which means: there are two types right now.

Journal-Piblications
Conference Publications

each of them have areas(each paper under these types has an area field).
So my desired output is.

Journal-Piblications

Area 1
papers

Area 2
papers

Conference-Publications

Area 1
papers

Area 2
papers


<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<Publications>

<!--<Journal-Publications>-->
<Paper> <!--paper 6-->
<Type>Journal-Publications</Type>
<Area>A</Area>
<Author>
<Name>abc</Name>
</Author>
<Author>
<Name>abc</Name>
</Author>


<Topic>
abc
</Topic>
<Month >
</Month>
<Year>1996</Year>
<Abstract-link></Abstract-link>
<Full-paper-link></Full-paper-link>
<Abstract></Abstract>
<Conference>abc</Conference>
</Paper>

<Paper>
<Type>Journal-Publications</Type>
<Area>B</Area>
<Author>
<Name>abc</Name>
</Author>
<Author>
<Name>abc</Name>
</Author>


<Topic>
abc
</Topic>
<Month >
</Month>
<Year>1993</Year>
<Abstract-link></Abstract-link>
<Full-paper-link></Full-paper-link>
<Abstract></Abstract>
<Conference>abc</Conference>
</Paper>

<Paper> <!--paper 8 done-->
<Type>Journal-Publications</Type>
<Area>C</Area>
<Author>
<Name>abc</Name>
</Author>
<Author>
<Name>abc</Name>
</Author>
<Topic>
hbaca</Topic>
<Month >
</Month>
<Year>1993</Year>
<Abstract-link></Abstract-link>
<Full-paper-link></Full-paper-link>
<Abstract></Abstract>
<Conference>gh</Conference>
</Paper>


<!--</Journal-Publications>-->

<!--<Conference-publications>-->



<Paper> <!--paper 8 done-->
<Type>Conference-publications</Type>
<Area>C</Area>
<Author>
<Name>abc</Name>
</Author>
<Author>
<Name>abc</Name>
</Author>
<Topic>
hbaca</Topic>
<Month >
</Month>
<Year>1993</Year>
<Abstract-link></Abstract-link>
<Full-paper-link></Full-paper-link>
<Abstract></Abstract>
<Conference>gh</Conference>
</Paper>



<Paper> <!--paper 8 done-->
<Type>Conference-publications</Type>
<Area>B</Area>
<Author>
<Name>abc</Name>
</Author>
<Author>
<Name>abc</Name>
</Author>
<Topic>
hbaca</Topic>
<Month >
</Month>
<Year>1993</Year>
<Abstract-link></Abstract-link>
<Full-paper-link></Full-paper-link>
<Abstract></Abstract>
<Conference>gh</Conference>
</Paper>

</Publications>

and following is the xslt I am using.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:url="http://www.jclark.com/xt/java/java.net.URLEncoder"
exclude-result-prefixes="url">

<xsl:key name="rows" match="Paper" use="Area" />
<xsl:template match="Publications">


<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>abcd</title>
<link href="../css/stylesheet.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>

<xsl:apply-templates
select="Paper[generate-id(.) = generate-id(key('rows', Area)[1])]" >
<!-- <xsl:if test="Type='Journal-Publications'">-->
<xsl:sort select="Area"/> <!-- Select area alphabatecially. Group By-->
<!-- </xsl:if> -->
</xsl:apply-templates>

</body>
</html>

</xsl:template>

<xsl:template match="Publications/Paper">
<br/>

<b><xsl:value-of select="Area" /></b> <!-- For each area selected above select all papers-->
<br/>
<xsl:for-each select="key('rows', Area)">
<xsl:sort select="Year" data-type="number" order="descending"/>
<xsl:sort select="@monthid" data-type="number" order="descending"/>
<br/>

<xsl:choose>
<xsl:when test="string-length(Full-Paper-link)"> <!--if there is link to paper-->
<a>
<xsl:attribute name="href"><xsl:value-of select="Full-paper-link"/> </xsl:attribute >
<span style="color: #0000ff">
<xsl:value-of select="Topic"/>
</span>
</a>
<br/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="Topic"/> <!--if there is no link to paper-->
<br/>
</xsl:otherwise>
</xsl:choose>

<xsl:for-each select="Author">
<xsl:if test="string-length(Name)">
<xsl:value-of select="Name"/>
<xsl:if test="not(position()=last())">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="position()=last()">
<br/>
</xsl:if>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="Conference"/>
<br/>
<xsl:if test="string-length(Abstract)">
<xsl:value-of select="Abstract"/>
<br/>
</xsl:if>
</xsl:for-each>

</xsl:template>


</xsl:stylesheet>


Your help is appreciated.

Thanks.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.