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 April 5th, 2006, 04:30 PM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouping in XSLT at same level of hierarchy...

Hi,

I have an input XML that looks like
<Major>
  <Jurisdiction>
    <Class>
       <Name>
       <State>
       <Age>
       <Gender>
   </Class>
  <School>
</Major>

I am trying to regroup this using XSLT as

<Group>
   <Jurisdiction>
       <Age>
          <Value>21</Value>
          <Name></Name>
          <Gender></Gender>
   </State>
</Group>.

Below is my XSLT, but it doesn't really group. It only returns the first matching combination.. Can u plz see if you have a clue???

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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"/>

    <xsl:variable name="pu" select="/*/*/*/AGE[not(normalize-space(.) = ../../preceding::AGE)] "/>

    <xsl:variable name="id" select="/*/*/*/STATE[normalize-space(.)='NY']"/>
    <xsl:variable name="nid" select="/*/*/*/STATE[not(normalize-space(.)='NY')]"/>

    <xsl:template match="Major">
    <xsl:copy>


    <Jurisdiction>
            <xsl:for-each select="$id">


        <xsl:for-each select="../AGE[not(normalize-space(.) = normalize-space(preceding::AGE))]">
         <Age>

          <xsl:variable name="udname" select="."/>
                <Value>
                    <xsl:value-of select="$udname"></xsl:value-of>
                </Value>
                <xsl:for-each select="../AGE[normalize-space(.)=$udname]">
                        <xsl:copy-of select="../.."/>
                </xsl:for-each>

         </Age>
         </xsl:for-each>


            </xsl:for-each>
    </Jurisdiction>
    <Jurisdiction>
      <xsl:for-each select="$nid">

        <xsl:for-each select="../AGE[not(normalize-space(.) = normalize-space(preceding::AGE))]">
        <Age>

          <xsl:variable name="udname" select="."/>
                <Value>
                    <xsl:value-of select="$udname"></xsl:value-of>
                </Value>
                <xsl:for-each select="../AGE[normalize-space(.)=$udname]">
                        <xsl:copy-of select="../.."/>
                </xsl:for-each>

         <Age>
         </xsl:for-each>

      </xsl:for-each>
    </Jurisdiction>




    </xsl:copy>
    </xsl:template>


</xsl:stylesheet>


 
Old April 6th, 2006, 10:01 AM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anyone please help ...

 
Old April 6th, 2006, 10:12 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It would help if you supplied the input and output as well-formed XML documents, and used tags that matched those in your stylesheet. You're making your readers do a lot of extra work to save yourself a few keystrokes, and the result is that you don't get an answer.

My first recommendation for grouping problems would be: use XSLT 2.0. If you can't do that, my recommendation would be: use Muenchian grouping.

I can't see anything in this example that makes it different from the standard grouping examples found in every XSLT textbook, but that might be because you haven't explained it well enough.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping with XSLT 1.0 rodmcleay XSLT 1 January 14th, 2008 11:42 PM
Multiple Self Join w/Dynamic Level Hierarchy LiamLiamLiam SQL Language 0 August 17th, 2007 10:21 AM
XSLT Going up a level from current node. lafilip XSLT 4 February 23rd, 2007 03:06 PM
XSLT - 2 level grouping & sequencing krayan001 XSLT 3 June 27th, 2005 01:23 PM
Non-recursive Data multi-level grouping jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 30th, 2004 03:42 PM





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