xsl-list
[Top] [All Lists]

Re: [xsl] Selecting non-duplicate nodes

2011-10-12 12:47:05
Hi Brandon,
That works on the sample input perfectly. I'll integrate it into the full code now and run it on the full data set. I'll let you know how that turns out.

Thanks,
Mark

-----Original Message----- From: Brandon Ibach
Sent: Wednesday, October 12, 2011 10:37 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Selecting non-duplicate nodes

The following seems to work to generate the contents of the
"FormatButtons" element, leaving everything else in your XSLT the
same.  The "select" grabs all of the Formats in Stamps having the
current Formats, the "group-by" filters out the duplicates and the
"select" on the "copy-of" filters out the current Formats.

       <xsl:for-each-group select="../../Stamp[Formats/@*[name(.) =
$format] = $number]/Formats"
                           group-by="concat(name(@*), '=', @*)">
<xsl:copy-of select="self::*[not(@*[name(.) = $format] = $number)]"/>
       </xsl:for-each-group>

-Brandon :)


On Wed, Oct 12, 2011 at 11:33 AM, Mark <mark(_at_)knihtisk(_dot_)org> wrote:
I posted a similar problem last week that required a somewhat more complex
answer but received no responses to it,  so I have reduced my requirements
and simplified the problem substantially. 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>

where the <Formats se-tenant="365" appears twice. What I desire is:

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

Thanks,
Mark
------------------------------------------------------
[Input file and stylesheet]
---------------------------------------------
<Input>
 <Set>
  <Stamp>
    <CatNumbers pofis-number="105"/>
    <Formats souvenir-sheet="105"/>
    <Formats se-tenant="105"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="106"/>
    <Formats souvenir-sheet="105"/>
    <Formats se-tenant="105"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="107"/>
    <Formats souvenir-sheet="105"/>
    <Formats se-tenant="107"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="108"/>
    <Formats souvenir-sheet="105"/>
    <Formats se-tenant="107"/>
  </Stamp>
 </Set>
 <Set>
  <Stamp>
    <CatNumbers pofis-number="146"/>
    <Formats souvenir-sheet="146"/>
    <Formats se-tenant="146"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="147"/>
    <Formats souvenir-sheet="146"/>
    <Formats se-tenant="146"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="148"/>
    <Formats souvenir-sheet="146"/>
    <Formats se-tenant="146"/>
  </Stamp>
 </Set>
 <Set>
  <Stamp>
    <CatNumbers pofis-number="244"/>
    <Formats coupon="244"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="245"/>
    <Formats souvenir-sheet="245"/>
  </Stamp>
 </Set>
 <Set>
  <Stamp>
    <CatNumbers pofis-number="365"/>
    <Formats souvenir-sheet="365"/>
    <Formats se-tenant="365"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="366"/>
    <Formats souvenir-sheet="365"/>
    <Formats se-tenant="365"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="367"/>
    <Formats souvenir-sheet="365"/>
    <Formats coupon="367"/>
  </Stamp>
  <Stamp>
    <CatNumbers pofis-number="368"/>
    <Formats souvenir-sheet="365"/>
    <Formats coupon="368"/>
  </Stamp>
 </Set>
</Input>

--------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"; exclude-result-prefixes="xs
xd"
 version="2.0">

 <xsl:strip-space elements="*"/>
 <xsl:template match="Input">
  <xsl:element name="Output">
    <xsl:apply-templates/>
  </xsl:element>
 </xsl:template>

 <xsl:template match="Set">
  <!-- <xsl:apply-templates mode="stamp"/> -->
  <xsl:apply-templates mode="formats"/>
 </xsl:template>

 <xsl:template match="Stamp" mode="formats">
  <xsl:apply-templates mode="formats"/>
 </xsl:template>

 <xsl:template match="Formats" mode="formats">
  <xsl:if test="@* eq ../CatNumbers/@pofis-number">
    <xsl:element name="FormatPage">
      <xsl:copy-of select="@*"/>
      <xsl:variable name="format" select="name(@*)"/>
      <xsl:variable name="number" select="@*"/>
      <xsl:element name="FormatButtons">
        <xsl:for-each-group select="../../Stamp" group-by="Formats">
          <xsl:for-each select="current-group()">
            <xsl:if test="Formats/@*[name(.)=$format]=$number">
              <Formats>
                <xsl:copy-of select="Formats/@*[not(name(.)=$format)]"/>
              </Formats>
            </xsl:if>
          </xsl:for-each>
        </xsl:for-each-group>
      </xsl:element>
    </xsl:element>
  </xsl:if>
 </xsl:template>

</xsl:stylesheet


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--