[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xml to xml issue in XSLT2.0

Subject: Re: xml to xml issue in XSLT2.0
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Nov 2007 13:34:10 -0500
Re:  xml to xml issue in XSLT2.0
At 2007-11-19 10:21 -0800, chun ji wrote:
I was trying to convert this xml file into a new one
in XSLT 2.0, but failed. The main issue is I have to
deal with one group-by with two level of elements: tab
and sub. I could not find any way to work around with
it. Help if you can.

You don't say what aspect of grouping you are having a problem with.


Below is a solution ... it is straightforward when grouping with XSLT 2 to act on the current group.

Note that the current element within a <xsl:for-each-group> is the first member of the group.

I hope this helps.

. . . . . . . . . . Ken


T:\ftemp>type chun.xml <?xml version="1.0" encoding="UTF-8"?> <perm_testing> <user name="SFO"> <tab name="YourSource"> <sub name="Client"> <checkpoint name="View" value="no"/> </sub> </tab> <tab name="Requisition"> <sub name="General Info"> <checkpoint name="View" value="yes"/> </sub> </tab> <tab name="Requisition"> <sub name="General Info"> <checkpoint name="Create" value="no"/> </sub> </tab> <tab name="Requisition"> <sub name="General Info"> <checkpoint name="Edit" value="no"/> </sub> </tab> <tab name="Requisition"> <sub name="Discussion"> <checkpoint name="View" value="no"/> </sub> </tab> <tab name="Requisition"> <sub name="Discussion"> <checkpoint name="Create" value="yes"/> </sub> </tab> <tab name="Requisition"> <sub name="Discussion"> <checkpoint name="Edit" value="no"/> </sub> </tab> <tab name="Requisition"> <sub name="Resume/Quote"> <checkpoint name="View" value="no"/> </sub> </tab> </user> <user name="ABC"> <tab name="YourSource"> <sub name="Client"> <checkpoint name="View" value="yes"/> </sub> </tab> <tab name="Requisition"> <sub name="General Info"> <checkpoint name="View" value="yes"/> </sub> </tab> <tab name="Requisition"> <sub name="General Info"> <checkpoint name="Create" value="no"/> </sub> </tab> </user> </perm_testing>

T:\ftemp>type chun.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="user">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:for-each-group select="tab" group-by="@name">
      <tab name="{@name}">
        <xsl:for-each-group select="current-group()/sub" group-by="@name">
          <sub name="{@name}">
            <xsl:apply-templates select="current-group()/checkpoint"/>
          </sub>
        </xsl:for-each-group>
      </tab>
    </xsl:for-each-group>
  </xsl:copy>
</xsl:template>

<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>


</xsl:stylesheet> T:\ftemp>call xslt2 chun.xml chun.xsl chun.out

T:\ftemp>type chun.out
<?xml version="1.0" encoding="UTF-8"?>
<perm_testing>
   <user name="SFO">
      <tab name="YourSource">
         <sub name="Client">
            <checkpoint name="View" value="no"/>
         </sub>
      </tab>
      <tab name="Requisition">
         <sub name="General Info">
            <checkpoint name="View" value="yes"/>
            <checkpoint name="Create" value="no"/>
            <checkpoint name="Edit" value="no"/>
         </sub>
         <sub name="Discussion">
            <checkpoint name="View" value="no"/>
            <checkpoint name="Create" value="yes"/>
            <checkpoint name="Edit" value="no"/>
         </sub>
         <sub name="Resume/Quote">
            <checkpoint name="View" value="no"/>
         </sub>
      </tab>
   </user>
   <user name="ABC">
      <tab name="YourSource">
         <sub name="Client">
            <checkpoint name="View" value="yes"/>
         </sub>
      </tab>
      <tab name="Requisition">
         <sub name="General Info">
            <checkpoint name="View" value="yes"/>
            <checkpoint name="Create" value="no"/>
         </sub>
      </tab>
   </user>
</perm_testing>
T:\ftemp>rem Done!



--
Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.