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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Daniel FrechetteSubject: Not grouping all nodes
Author: Daniel Frechette
Date: 22 May 2006 01:00 PM
Originally Posted: 22 May 2006 12:54 PM
Hi,

I want to group activities by distance (e.g. unspecified, on site, within 1 km, within 5 km, etc.). For each activity, a distance may or may not be specified. Activities with no distances, are grouped under 'unspecified'.

The problem is that when no distance is specified and non activity nodes are present (see 'facilities' node in XML file), activities with no distances are simply ignored. Why?? Is there a solution to this problem?

Thank you for your help.

Expected output:
<distance value="Unspecified">
<activity>Kayak</activity>
</distance>
<distance value="On site">
<activity>Golf</activity>
<activity>Tennis</activity>
</distance>
<distance value="Within 1 km">
<activity>Football</activity>
</distance>
<distance value="Within 5 km">
<activity>Ski</activity>
</distance>

Here is my XSL script:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="grp" match="value" use="attribute[@name='value']"/>
<xsl:template match="/">
<xsl:for-each select="//property/attribute[@name='activities']">
<xsl:for-each select="value[count(.|key('grp',attribute[@name='value'])[1])=1]">
<xsl:sort select="attribute[@name='value']/value/@order" />
<distance>
<xsl:attribute name="value">
<xsl:value-of select="attribute[@name='value']/value" />
<xsl:if test="not(attribute[@name='value']/value)">
<xsl:text>Unspecified</xsl:text>
</xsl:if>
</xsl:attribute>
<xsl:for-each select="key('grp',attribute[@name='value'])">
<xsl:sort select="attribute[@name='literal']/value"/>
<activity>
<xsl:value-of select="attribute[@name='literal']/value" />
</activity>
</xsl:for-each>
</distance>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Here is my XML data:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<model>
<property>
<attribute name="activities">
<value>
<attribute name="literal">
<value>Kayak</value>
</attribute>
<attribute name="value"></attribute>
</value>
<value>
<attribute name="literal">
<value>Ski</value>
</attribute>
<attribute name="value">
<value order="3">Within 5 km</value>
</attribute>
</value>
<value>
<attribute name="literal">
<value>Tennis</value>
</attribute>
<attribute name="value">
<value order="1">On site</value>
</attribute>
</value>
<value>
<attribute name="literal">
<value>Football</value>
</attribute>
<attribute name="value">
<value order="2">Within 1 km</value>
</attribute>
</value>
<value>
<attribute name="literal">
<value>Golf</value>
</attribute>
<attribute name="value">
<value order="1">On site</value>
</attribute>
</value>
</attribute>
<attribute name="facilities">
<value>
<attribute name="literal">
<value>Bar / Lounge</value>
</attribute>
<attribute name="value"></attribute>
</value>
</attribute>
</property>
</model>
</data>

Postnext
Ivan PedruzziSubject: Not grouping all nodes
Author: Ivan Pedruzzi
Date: 22 May 2006 06:14 PM
Hi Daniel,

Unfortunately empty values are not indexed; try the attached solution



Hope this helps
Ivan Pedruzzi
Stylus Studio Team


Documentactivities.xsl

Posttop
Daniel FrechetteSubject: Not grouping all nodes
Author: Daniel Frechette
Date: 22 May 2006 08:41 PM
Hi Ivan.

Your solution does exactly what I want.

Thank you,

Daniel

   
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.