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

Re: best-technique for selective group and merge?

Subject: Re: best-technique for selective group and merge?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 02 Mar 2004 12:44:36 -0500
washington id template
At 2004-03-02 08:43 -0800, James A. Robinson wrote:
The feature can contain multiple configs,
each of which I want to merge across features:
...
I want to be able to select /config_datastore/site/* and perform selective
grouping (on feature @name) and merging (on the feature/config elements)
to return:
...

I found I could wrap my head around this problem using variables instead of keys. An example is below giving your desired results. Note how I take advantage of the node-set comparison of a single value to a set of values to get from all configs only those whose feature's name is in a set of names.


I hope this helps.

.................... Ken


T:\ftemp>type jim.xml <?xml version="1.0"?> <config_datastore> <feature name="a"> <config id="1"> <param id="x">x</param> </config> <config id="2"> <param id="xx">xx</param> </config> <config id="3"> <param id="xxx">xxx</param> </config> </feature> <feature name="b"> <config id="1"> <param id="y">y</param> </config> <config id="2"> <param id="yy">yy</param> </config> </feature> <feature name="c"> <config id="1"> <param id="z">z</param> </config> <config id="2"> <param id="zz">zz</param> </config> </feature> <site> <has_feature name="a"/> <has_feature name="c"/> </site> </config_datastore>

T:\ftemp>type jim.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output indent="yes"/>

<xsl:template match="/">
  <result>
    <xsl:variable name="configs"
                  select="/*/feature[@name=/*/site/has_feature/@name]/config"/>
    <xsl:for-each select="$configs">
      <xsl:if test="generate-id(.)=
                    generate-id($configs[@id=current()/@id])">
        <config id="{@id}">
          <xsl:copy-of select="$configs[@id=current()/@id]/*"/>
        </config>
      </xsl:if>
    </xsl:for-each>
  </result>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>saxon jim.xml jim.xsl
<?xml version="1.0" encoding="utf-8"?>
<result>
   <config id="1">
      <param id="x">x</param>
      <param id="z">z</param>
   </config>
   <config id="2">
      <param id="xx">xx</param>
      <param id="zz">zz</param>
   </config>
   <config id="3">
      <param id="xxx">xxx</param>
   </config>
</result>
T:\ftemp>rem Done!



--
US XSL training: Washington,DC March 15; San Francisco,CA March 22
World-wide on-site corporate, government & user group XML 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 Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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-2013 All Rights Reserved.