|
Subject: Re: [xsl] best-technique for selective group and merge? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 02 Mar 2004 12:44:36 -0500 |
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: ...
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: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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] best-technique for select, James A. Robinson | Thread | Re: [xsl] best-technique for select, Wendell Piez |
| Re: [xsl] best-technique for select, James A. Robinson | Date | Re: [xsl] reccursive sum ?, David Carlisle |
| Month |