|
Subject: Re: [xsl] combining common data within groups. From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Tue, 04 Nov 2008 12:48:52 +0100 |
This is a new area for me. Need to eliminate duplicates that occur within sub-groups.
XML Input example: <?xml version="1.0"?> <root> <boxes> <box_sizes> <value>square</value> </box_sizes> <box_sizes> <value>square</value> </box_sizes> </boxes> <boxes> <box_sizes> <value>round</value> </box_sizes> <box_sizes> <value>square</value> </box_sizes> </boxes> <color1>red</color1> <color2>blue</color2> </root>
Desired output: <?xml version="1.0" encoding="utf-8"?> <root> <color1>red</color1> <boxes> <box_sizes> <value>square</value> </box_sizes> </boxes> <boxes> <box_sizes> <value>round</value> <value>square</value> </box_sizes> </boxes> </root>
As you can see, I want to eliminate duplicate occurances of
<box_sizes/value> within the <boxes> group.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="by-value"
match="box_sizes"
use="concat(generate-id(parent::boxes), '_', value)"/> <xsl:template match="root">
<xsl:copy>
<xsl:apply-templates select="color1"/>
<xsl:apply-templates select="boxes"/>
</xsl:copy>
</xsl:template> <xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>Martin Honnen http://JavaScript.FAQTs.com/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] combining common data within , Andy.Lewis | Thread | [xsl] determine the number of payme, Caroline Umali |
| Re: [xsl] XPath "//", speed, and Sa, Tony Graham | Date | [xsl] typing the input from within , Andrew Welch |
| Month |