xsl-list
[Top] [All Lists]

Re: [xsl] Selecting non-duplicate nodes

2011-10-12 13:01:17
Am 12.10.2011 um 17:33 schrieb Mark:

My question now is: how can I change this stylesheet so that for the listed 
input, no <FormatButtons> in the output contains more than one copy of a 
<Format> with the same attribute name and value? That is, where the current 
output is, for example:

<FormatPage souvenir-sheet="365">
 <FormatButtons>
   <Formats se-tenant="365"/>
   <Formats se-tenant="365"/>
   <Formats coupon="367"/>
   <Formats coupon="368"/>
 </FormatButtons>
</FormatPage>

Mark,

If a node in your sample is a duplicate of another node can be retrieved from 
the attribute names and their values. So IMO the grouping key could be a 
serialization of them. In other words, we look at the source as if we were a 
text processor, like this:

<xsl:template match="FormatButtons">
  <xsl:copy>
    <xsl:for-each-group select="Formats"
        group-by="string-join(
          for $i in 1 to count(@*) 
            return concat(name(@*[$i]), '=', @*[$i]), ' ')">
      <xsl:apply-templates select="."/>
    </xsl:for-each-group>
  </xsl:copy>
</xsl:template>

In XML the order of attributes is usually irrelevant, but the above solution 
does not ignore order. But it works with any number of attributes.

- Michael Müller-Hillebrand

--
_______________________________________________________________
Michael Müller-Hillebrand: Dokumentation Technology
Adobe Certified Expert, FrameMaker
Consulting and Training, FrameScript, XML/XSL, Unicode
Blog [de]: http://cap-studio.de/





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--