Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2011, 12:29 AM
Registered User
 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Extracting child node name value and arranging alphabetically with grouping

Hi All,

Below is the XML snippet

<site-map>
<segment>
<node visible-in-breadcrumbs="true"><name>Product</name>
<node visible-in-breadcrumbs="true"><name>Academic</name>
<ExternalLink>http://web.lis.com/</ExternalLink>
</node>
<node visible-in-breadcrumbs="true"><name>back Screening one</name>
<ExternalLink>http://www.acc.com</ExternalLink>
</node>
<node visible-in-breadcrumbs="true"><name>acc</name>
<ExternalLink>http://www.acc.com</ExternalLink>
</node>
</node>
<node visible-in-breadcrumbs="true"><name>About</name>
<node visible-in-breadcrumbs="true"><name>history</name>
<ExternalLink>http://web.his.com/</ExternalLink>
</node>
<node visible-in-breadcrumbs="true"><name>Careers</name>
<ExternalLink>http://www.acc.com/careers</ExternalLink>
</node>
</node>
</segment>
</site-map>


I want to display all the child node of "Products". Secondly, I would like to render HTML output as below:

A
academy
Accuratez

B
back Screening

Conditions are:
1. Grouping all the node under their respective initial.
2. <Name> tag value starting with small letters should appear first. But if say "Johan" and "johan" are two different values then "johan" shall appear before "Johan".
3. If visible-in-breadcrumbs value is true then only parent node shall be selected and respectively based on the same child nodes shall be displayed.

It would be great if anyone can provide me solution based on the above requirement would be highly appreciated.

Regards,
Ace
 
Old July 26th, 2011, 04:54 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

In XSLT 2.0 you group by using the xsl:for-each-group instruction. In XSLT 1.0 you have to do more complicated grouping via Muenchian grouping (search google, or look at the first post in this forum for more details).

Something like this does what you want:

Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
   <xsl:output indent="yes" method="text"/>
   <xsl:template match="/">
	   <xsl:for-each-group select="//node[name='Product']/node" group-by="upper-case(substring(name,1,1))">
	   	<xsl:value-of select="current-grouping-key()"/><xsl:text>
</xsl:text>
	   	<xsl:for-each select="current-group()">
	   		<xsl:sort select="substring(name,1,1)" case-order="lower-first"/>
	   		<xsl:sort select="name"/>
	   			<xsl:text>	</xsl:text><xsl:value-of select="name"/><xsl:text>
</xsl:text>
	   		</xsl:for-each>
	   	</xsl:for-each-group>
   </xsl:template>
</xsl:stylesheet>
As for point 3 - you don't give any indication from your example input and expected output what this actually means - there are no values for false in the visible-in-breadcrumbs attribute example input showing how they would be handled differently in the output, so I can't really help you with that bit without more information.

Sam
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting second chlid element of same parent node using following-sibling ROCXY XSLT 3 May 22nd, 2009 10:56 AM
how to find child node when there is mentioned (child::*) mlohokare XSLT 3 May 12th, 2009 12:40 PM
Accessing a node bases on child node value musman0047 XSLT 1 February 27th, 2009 12:26 PM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.