Re: [xsl] xml to xml issue in XSLT2.0

Subject: Re: [xsl] xml to xml issue in XSLT2.0
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Nov 2007 14:20:44 -0500
At 2007-11-19 10:56 -0800, chun ji wrote:
Hi Ken
Thanks for the help, But yours is  :
...
While the one that I am looking for is something like

I apologize I missed the difference.


Would you please check the one below for accuracy?

As I read section 14.2, the current grouping key is an atomic value, so I've created an atomic value from the two items in such a way that they are delimited by a character unlikely to show up in either value. The carriage returns in line-ending sequences are normalized to linefeed characters, so the only carriage return to survive would be one coded as a numeric character reference in your source, which is quite unlikely.

Sorry 'bout that.

. . . . . . . . . . . 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/sub"
                        group-by="concat(../@name,'&#xd;',@name)">
      <tab name="{../@name}">
        <sub name="{@name}">
          <xsl:apply-templates select="current-group()/checkpoint"/>
        </sub>
      </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>
      </tab>
      <tab name="Requisition">
         <sub name="Discussion">
            <checkpoint name="View" value="no"/>
            <checkpoint name="Create" value="yes"/>
            <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"/>
            <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