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 November 7th, 2012, 06:29 AM
Registered User
 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default Grouping by attribute

I have XSLT 2.0 (Saxon free edition 9.H.E)

my xml
<Group>
<Detail Custno="111" date="2012-11-01t06:00:00">
<Order Nr="1" name="xxx"/>
<Order Nr="2" name="yyy"/>
<Product id="1" type="a" lenght="10" height="15"/>
<Product id="1" type="a" lenght="105" height="15"/>
<Product id="1" type="b" lenght="12" height="15"/>
<Product id="1" type="a" lenght="13" height="15"/>
<Product id="1" type="b" lenght="10" height="13"/>
</Detail>
</Group>


Desired output

<Group>
<Time>2012-11-07T05:00:00</Time>
<Detail>
<CustNo>111</CustNo>
<OrderList>
<Order>
<Nr>1</Nr>
<name>xxx</name>
</Order>
<Order>
<Nr>2</Nr>
<name>yyy</name>
</Order>
</OrderList>
<ProductList>
<Product>
<id>1</id>
<type>a</type>
<Dimension>
<lenght>10</lenght>
<height>15</height>
</Dimension>
<Dimension>
<lenght>105</lenght>
<height>15</height>
</Dimension>
<Dimension>
<lenght>13</lenght>
<height>15</height>
</Dimension>
</Product>
<Product>
<id>1</id>
<type>b</type>
<Dimension>
<lenght>12</lenght>
<height>15</height>
</Dimension>
<Dimension>
<lenght>10</lenght>
<height>13</height>
</Dimension>
</Product>
</ProductList>
</Detail>
</Group>




I tried using xsl:for-each-group but i'm getting this error "xsl:for-each-group not yet implemented"

Please help
 
Old November 7th, 2012, 06:50 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well if you really use Saxon 9 then you shouldn't get that error message. That error message suggests you use an XSLT 1.0 processor like Microsoft's XslCompiledTransform in .NET 3.5 and 4.0 respectively Visual Studio. So make sure you use Saxon 9 and not the built-in XSLT processor in .NET or Visual Studio.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old November 7th, 2012, 06:55 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Also, when reporting an error in your XSLT it can be helpful to show your XSLT, rather than us trying to guess what it looks like.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old November 7th, 2012, 07:55 AM
Registered User
 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default my xslt

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>

<xsl:key name="type" match="Product" use="@type" />

<xsl:template match="Group">
<xsl:message>
<Envelope>
<Time>
<xsl:value-of select="format-dateTime(current-dateTime(), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')" />
</Time>
<Detail>
<CustNo>
<xsl:value-of select="//Group/Detail/@CustNo"/>
</CustNo>
<OrderList>
<xsl:for-each select="//Order">
<Order>
<Nr>
<xsl:value-of select="@Nr"/>
</Nr>
<name>
<xsl:value-of select="@name"/>
</name>
</Order>
</xsl:for-each>
</OrderList>
<ProductList>
<xsl:for-each-group select="Detail/Product" group-by="@type">
<Product>
<id>
<xsl:value-of select="@id"/>
</id>
<type>
<xsl:value-of select="@type"/>
</type>
<xsl:for-each select="current-group()">
<Dimension>
<lenght>
<xsl:value-of select="@lenght" />
</lenght>
<height>
<xsl:value-of select="@height" />
</height>
</Dimension>
</xsl:for-each>
</Product>
</xsl:for-each-group>
</ProductList>
</Detail>
</Envelope>
</xsl:message>
</xsl:template>
</xsl:stylesheet>



i changed some in my xslt.
im able to get the o/p now but the cust no is not displayed . Can you pls let me know where is the error
 
Old November 7th, 2012, 01:27 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Case matters with XML names so instead of
Code:
<xsl:value-of select="//Group/Detail/@CustNo"/>
you need to make sure you use the same case as the elements and attributes in the input XML have and there you have "Custno" attribute. Based on that I think you want
Code:
<xsl:value-of select="Detail/Custno"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old November 8th, 2012, 12:28 PM
Registered User
 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Martin.
I overlooked that thanks for pointing it out





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select nodes whose attribute matches another node's attribute? nikolai XSLT 5 April 18th, 2018 11:30 AM
XSLT - Grouping by Attribute but same elements vinaura XSLT 2 July 18th, 2007 10:34 PM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
Grouping by attribute aiyer0912 XSLT 1 November 13th, 2006 06:47 AM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM





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