logo
down
shadow

XSLT Aggregation using sort with Muenchian Method for min and max


XSLT Aggregation using sort with Muenchian Method for min and max

Content Index :

XSLT Aggregation using sort with Muenchian Method for min and max
Tag : xml , By : Hunter
Date : November 28 2020, 09:01 AM

hop of those help? I understand the Muenchian Method indexes the entire document at first read. But how can one sort prior or within grouping but not on its key? Specifically, how can I order a sibling of the key in order to calculate min and max of a series of element values? , How about this way?
XSLT 1.0
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="co-by-ind" match="bigcompany" use="industry" />

<xsl:template match="/data">
    <xsl:copy>
        <xsl:for-each select="bigcompany[generate-id() = generate-id(key('co-by-ind', industry)[1])]">  
            <xsl:sort select="industry" data-type="text" order="ascending"/>                   
            <!-- variables -->
            <xsl:variable name="curr-group" select="key('co-by-ind', industry)" />
            <xsl:variable name="income-sorted">
                <xsl:for-each select="$curr-group">
                    <xsl:sort select="netincome" data-type="number" order="ascending"/>
                    <xsl:copy-of select="netincome"/>
                </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="income-sorted-set" select="exsl:node-set($income-sorted)/netincome" />
            <!-- output -->
            <aggdata>
                <xsl:copy-of select="industry"/>        
                <SumOfRevenue>
                    <xsl:value-of select="sum($curr-group/revenue)"/>
                </SumOfRevenue>
                <AvgOfAssets>
                    <xsl:value-of select="sum($curr-group/assets) div count($curr-group/assets)"/>
                </AvgOfAssets>
                <AvgOfEquity>
                    <xsl:value-of select="sum($curr-group/equity) div count($curr-group/equity)"/>
                </AvgOfEquity>
                <MaxOfIncome>
                    <xsl:value-of select="$income-sorted-set[last()]"/>
                </MaxOfIncome>
                <MinOfIncome>
                    <xsl:value-of select="$income-sorted-set[1]"/>
                </MinOfIncome>
                <AvgOfStockPrice>
                    <xsl:value-of select="sum($curr-group/stockprice) div count($curr-group/stockprice)"/>
                </AvgOfStockPrice>
                <SumOfEmployees>
                    <xsl:value-of select="sum($curr-group/employees)"/>
                </SumOfEmployees>
            </aggdata>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to group in XSLT using Muenchian Method?


Tag : xml , By : Dave M
Date : March 29 2020, 07:55 AM
hop of those help? I'm quite new to XSLT and I'm using XSLT 1.0. Now I need to group some stuff in a quite big XML file. There are lots of examples out there but none worked for me for some reason. I'm able to group the info I want, but I also get some extra text in my output xml. Here's what I'm doing right now; , Add a template doing
<xsl:template match="/">
  <xsl:apply-templates select="//items"/>
</xsl:template>

XSLT Muenchian Method


Tag : xml , By : Search Classroom
Date : March 29 2020, 07:55 AM
I hope this helps . I'm working with an XSLT that someone else designed. Back in that time the xml structure was like this: , What you could try is replace the code
<xsl:key name="module-index" match="errata_section" use="module_impacted"/>

...

<xsl:for-each select="//errata_section[generate-id(.)=generate-id(key('module-index', module_impacted)[1])]">
 <xsl:sort select="module_impacted"/>

<!-- Do some processing -->

</xsl:for-each>
<xsl:key name="module-index" match="errata_section" use="module_impacted"/>
<xsl:key name="group" match="errata_section/module_impacted" use="."/>

...

<xsl:for-each select="//errata_section/module_impacted[generate-id() = generate-id(key('group', .)[1])]">">
 <xsl:sort select="."/>
 <xsl:variable name="current-group" select="key('module-index', .)"/>
 <xsl:variable name="current-grouping-key" select="."/>

<!-- Do some processing -->

</xsl:for-each>
<xsl:for-each select="//errata_section[generate-id(.)=generate-id(key('module-index', module_impacted)[1])]">
 <xsl:sort select="module_impacted"/>

    <xsl:variable name="current_module"><xsl:value-of select="module_impacted"/></xsl:variable> 
<xsl:for-each select="//errata_section/module_impacted[generate-id() = generate-id(key('group', .)[1])]">">
 <xsl:sort select="."/>
 <xsl:variable name="current-group" select="key('module-index', .)"/>
 <xsl:variable name="current_module" select="."/>
<xsl:for-each select="key('module-index', module_impacted)">
<xsl:for-each select="$current-group">
<article>

  <errata_section id="e1" errata_type="bug">
    <title>e1</title>
    <module_impacted>m1</module_impacted>
    <module_impacted>m3</module_impacted>
  </errata_section>

  <errata_section id="e2" errata_type="bug">
    <title>e2</title>
    <module_impacted>m1</module_impacted>
    <module_impacted>m2</module_impacted>
  </errata_section>

  <errata_section id="e3" errata_type="bug">
    <title>e3</title>
    <module_impacted>m1</module_impacted>
    <module_impacted>m3</module_impacted>
  </errata_section>

</article>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="module-index" match="errata_section" use="module_impacted"/>

<xsl:template match="/">
  <xsl:for-each select="//errata_section[generate-id(.)=generate-id(key('module-index', module_impacted)[1])]">
    <xsl:sort select="module_impacted"/>
    <group key="{module_impacted}">
      <xsl:copy-of select="key('module-index', module_impacted)"/>
    </group>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
<group key="m1">
   <errata_section id="e1" errata_type="bug">
      <title>e1</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m3</module_impacted>
   </errata_section>
   <errata_section id="e2" errata_type="bug">
      <title>e2</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m2</module_impacted>
   </errata_section>
   <errata_section id="e3" errata_type="bug">
      <title>e3</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m3</module_impacted>
   </errata_section>
</group>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="module-index" match="errata_section" use="module_impacted"/>
<xsl:key name="group" match="errata_section/module_impacted" use="."/>

<xsl:template match="/">
  <xsl:for-each select="//errata_section/module_impacted[generate-id() = generate-id(key('group', .)[1])]">
    <xsl:sort select="."/>
    <xsl:variable name="current-group" select="key('module-index', .)"/>
    <xsl:variable name="current_module" select="."/>
    <group key="{$current_module}">
      <xsl:copy-of select="$current-group"/>
    </group>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
<group key="m1">
   <errata_section id="e1" errata_type="bug">
      <title>e1</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m3</module_impacted>
   </errata_section>
   <errata_section id="e2" errata_type="bug">
      <title>e2</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m2</module_impacted>
   </errata_section>
   <errata_section id="e3" errata_type="bug">
      <title>e3</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m3</module_impacted>
   </errata_section>
</group>
<group key="m2">
   <errata_section id="e2" errata_type="bug">
      <title>e2</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m2</module_impacted>
   </errata_section>
</group>
<group key="m3">
   <errata_section id="e1" errata_type="bug">
      <title>e1</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m3</module_impacted>
   </errata_section>
   <errata_section id="e3" errata_type="bug">
      <title>e3</title>
      <module_impacted>m1</module_impacted>
      <module_impacted>m3</module_impacted>
   </errata_section>
</group>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl">

<xsl:output indent="yes" />
<xsl:strip-space elements="*"/>

<xsl:param name="dv" select="'VAZER'"/>

<xsl:key name="by-dv" match="errata_section" use="devices_impacted/device_name"/>

<xsl:variable name="err-rtf">
  <xsl:copy-of select="key('by-dv', $dv)"/>
</xsl:variable>

<xsl:variable name="err" select="exsl:node-set($err-rtf)"/>

<xsl:param name="show_review">no</xsl:param>

<xsl:key name="module-index" match="errata_section" use="module_impacted"/>

<xsl:key name="group" match="errata_section/module_impacted" use="."/>
<xsl:key name="device-index" match="errata_section" use="devices_impacted/device_name"/>

<xsl:template name="table_of_section_per_module">
  <xsl:element name="article">
      <xsl:attribute name="id">errata_module_impacted</xsl:attribute>
      <xsl:attribute name="arch"><xsl:value-of select='$dv'/></xsl:attribute>
      <title>Modules Impacted</title>

      <xsl:for-each select="$err//module_impacted[generate-id() = generate-id(key('group', .)[1])]">
          <xsl:sort select="."/>
          <xsl:variable name="current-group" select="key('module-index', .)"/>
          <xsl:variable name="current-grouping-key" select="."/>
          <xsl:variable name="num_of_sections" select="count(.)"/>
          <xsl:variable name="current_module" select="."/>

          <table>
              <xsl:attribute name="id">
                  <xsl:value-of select="generate-id($current-grouping-key)"/>
              </xsl:attribute>
              <title>
                  <xsl:text>Module </xsl:text>
                  <xsl:value-of select="$current_module"/>
                  <xsl:text> (</xsl:text><xsl:value-of select="$num_of_sections"/><xsl:text> section</xsl:text>
                  <!-- a little grammar ! -->
                  <xsl:if test="$num_of_sections&gt;1"><xsl:text>s</xsl:text></xsl:if><xsl:text>)</xsl:text>
              </title>
              <xsl:element name="tgroup"> 
                  <xsl:attribute name="cols">
                      <xsl:choose>
                          <xsl:when test='$show_review="yes"'>3</xsl:when>
                          <xsl:otherwise>2</xsl:otherwise>
                      </xsl:choose>
                  </xsl:attribute>
                  <xsl:element name="colspec"> 
                      <xsl:attribute name="colwidth">1*</xsl:attribute>
                      <xsl:attribute name="colname">_1</xsl:attribute>
                  </xsl:element>
                  <xsl:choose>
                      <xsl:when test='$show_review="yes"'>
                          <xsl:element name="colspec">
                              <xsl:attribute name="colwidth">6*</xsl:attribute>
                              <xsl:attribute name="colname">_2</xsl:attribute>
                          </xsl:element>
                          <xsl:element name="colspec">
                              <xsl:attribute name="colwidth">1*</xsl:attribute>
                              <xsl:attribute name="colname">_3</xsl:attribute>
                          </xsl:element>
                      </xsl:when>
                      <xsl:otherwise>
                          <xsl:element name="colspec">
                              <xsl:attribute name="colwidth">8*</xsl:attribute>
                              <xsl:attribute name="colname">_2</xsl:attribute>
                          </xsl:element>
                      </xsl:otherwise>
                  </xsl:choose>
                  <tbody>
                      <row>
                          <xsl:element name="entry">
                              <xsl:attribute name="morerows"> <xsl:value-of select="$num_of_sections"/></xsl:attribute>
                              <xsl:value-of select="$current_module"/>
                          </xsl:element>
                          <entry>Section</entry>
                          <xsl:if test='$show_review="yes"'>
                              <entry>Review status</entry>
                          </xsl:if>
                      </row>
                      <xsl:for-each select="$current-group">
                          <row>
                              <entry>
                                  <xsl:value-of select="@id" /><xsl:text>: </xsl:text>
                                  <xsl:element name="xref">
                                      <xsl:attribute name="linkend">sect_<xsl:value-of select="@id" />
                                  </xsl:attribute></xsl:element>
                              </entry>
                              <xsl:if test='$show_review="yes"'>
                                  <entry>
                                      <xsl:value-of select="review_status" />
                                  </entry>
                              </xsl:if>
                          </row>
                      </xsl:for-each>
                  </tbody>
              </xsl:element> <!-- tgroup element -->
          </table>
      </xsl:for-each>
  </xsl:element>
</xsl:template>
<xsl:template match="/">
 <book>
   <xsl:call-template name="table_of_section_per_module"/>
   </book>
   </xsl:template>
 </xsl:stylesheet>

XSLT Muenchian method complex


Tag : xml , By : rajiv
Date : March 29 2020, 07:55 AM
wish help you to fix your issue You were not far off, with your use of keys, but the main problem as far as I can see was you had some nested xsl:for-each statements, which weren't taking into account the context. For example
<xsl:for-each select="$ROOT_A/ES_PRODUCT/trailerProject/wontrailerproject/producer/ES_PERSON[generate-id() = generate-id(key('producers',@pe_fullname)[1])]">
   <xsl:variable name="thisProducer" select="@pe_fullname"/>
  <xsl:for-each select="p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL[generate-id() = generate-id(key('channels',@name)[1])]">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:output encoding="utf-8" indent="yes"/>
<xsl:key name="producers" match="trailers/ES_PRODUCT/trailerProject/wontrailerproject/producer/ES_PERSON" use="@pe_fullname"/>
<xsl:key name="channels" match="trailers/ES_PRODUCT/p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL" use="@name"/>
<xsl:key name="year" match="trailers/ES_PRODUCT" use="@year"/>
<xsl:key name="full" match="trailers/ES_PRODUCT" use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                             trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname, '|',
                                                             @year)"/>

<xsl:template match="/">
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
              xmlns:html="http://www.w3.org/TR/REC-html40">
        <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">

        </DocumentProperties>
        <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
            <AllowPNG/>
        </OfficeDocumentSettings>
        <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
            <WindowHeight>11595</WindowHeight>
            <WindowWidth>19200</WindowWidth>
            <WindowTopX>0</WindowTopX>
            <WindowTopY>0</WindowTopY>
            <ProtectStructure>False</ProtectStructure>
            <ProtectWindows>False</ProtectWindows>
        </ExcelWorkbook>
        <Styles>
            <Style ss:ID="Default" ss:Name="Normal">
                <Alignment ss:Vertical="Bottom"/>
                <Borders/>
                <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
                <Interior/>
                <NumberFormat/>
                <Protection/>
            </Style>
            <Style ss:ID="s70">
                <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
                <Interior ss:Color="#FFC000" ss:Pattern="Solid"/>
            </Style>
            <Style ss:ID="s74">
                <Borders>
                    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
                </Borders>
            </Style>
            <Style ss:ID="s75">
                <Borders>
                    <Border ss:Position="Bottom" ss:LineStyle="Double" ss:Weight="3"/>
                    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
                    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
                </Borders>
                <Interior ss:Color="#92D050" ss:Pattern="Solid"/>
            </Style>
        </Styles>
        <Worksheet ss:Name="Hoja1">
            <Table x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
                <Column ss:Width="66"/>
                <Column ss:AutoFitWidth="0" ss:Width="69"/>
                <xsl:variable name="ROOT_A" select="trailers"/>
                <xsl:variable name="distinct_channels" select="trailers/ES_PRODUCT/p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL[generate-id() = generate-id(key('channels',@name)[1])]" />
                <xsl:variable name="distinct_producers" select="$ROOT_A/ES_PRODUCT/trailerProject/wontrailerproject/producer/ES_PERSON[generate-id() = generate-id(key('producers',@pe_fullname)[1])]" />
                <xsl:variable name="distinct_years" select="$ROOT_A/ES_PRODUCT[generate-id() = generate-id(key('year',@year)[1])]" />
                <xsl:for-each select="$distinct_channels">
                    <xsl:variable name="thisChannel" select="@name"/>

                    <Row ss:Height="15.75">
                        <Cell ss:StyleID="s75">
                            <Data ss:Type="String">
                                <xsl:value-of select="$thisChannel"/>
                            </Data>
                        </Cell>
                        <xsl:for-each select="$distinct_producers">
                            <xsl:variable name="thisProducer" select="@pe_fullname"/>

                                <Cell ss:StyleID="s75">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisProducer"/>
                                    </Data>
                                </Cell>
                        </xsl:for-each>
                    </Row>

                    <xsl:for-each select="$distinct_years">
                        <xsl:variable name="thisYear" select="@year"/>

                            <Row ss:Height="15.75">
                                <Cell ss:StyleID="s74">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisYear"/>
                                    </Data>
                                </Cell>
                                <xsl:for-each select="$distinct_producers">
                                    <xsl:variable name="thisProducer" select="@pe_fullname"/>
                                        <Cell ss:StyleID="s74">
                                            <Data ss:Type="Number">
                                                <xsl:value-of select="count(key('full', concat($thisChannel, '|', $thisProducer, '|', $thisYear)))"/>
                                            </Data>
                                        </Cell>
                                </xsl:for-each>
                            </Row>
                    </xsl:for-each>
                </xsl:for-each>
            </Table>
            <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
                <PageSetup>
                    <Header x:Margin="0.3"/>
                    <Footer x:Margin="0.3"/>
                    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
                </PageSetup>
                <Print>
                    <ValidPrinterInfo/>
                    <HorizontalResolution>300</HorizontalResolution>
                    <VerticalResolution>300</VerticalResolution>
                </Print>
                <Selected/>
                <Panes>
                    <Pane>
                        <Number>3</Number>
                        <ActiveRow>6</ActiveRow>
                        <ActiveCol>2</ActiveCol>
                    </Pane>
                </Panes>
                <ProtectObjects>False</ProtectObjects>
                <ProtectScenarios>False</ProtectScenarios>
            </WorksheetOptions>
        </Worksheet>
    </Workbook>
</xsl:template>
</xsl:stylesheet>
<xsl:key name="producers_by_channel" match="trailers/ES_PRODUCT" 
                                     use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                 trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname)"/>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:output encoding="utf-8" indent="yes"/>

<xsl:key name="channels" match="trailers/ES_PRODUCT" use="p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name"/>
<xsl:key name="year" match="trailers/ES_PRODUCT" use="@year"/>
<xsl:key name="producers_by_channel" match="trailers/ES_PRODUCT" 
                                     use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                 trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname)"/>
<xsl:key name="full" match="trailers/ES_PRODUCT" use="concat(p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name, '|', 
                                                             trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname, '|',
                                                             @year)"/>

<xsl:template match="/">
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
              xmlns:html="http://www.w3.org/TR/REC-html40">
        <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">

        </DocumentProperties>
        <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
            <AllowPNG/>
        </OfficeDocumentSettings>
        <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
            <WindowHeight>11595</WindowHeight>
            <WindowWidth>19200</WindowWidth>
            <WindowTopX>0</WindowTopX>
            <WindowTopY>0</WindowTopY>
            <ProtectStructure>False</ProtectStructure>
            <ProtectWindows>False</ProtectWindows>
        </ExcelWorkbook>
        <!-- Styles go here -->
        <Worksheet ss:Name="Hoja1">
            <Table x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15">
                <Column ss:Width="66"/>
                <Column ss:AutoFitWidth="0" ss:Width="69"/>
                <xsl:variable name="ROOT_A" select="trailers"/>
                <xsl:variable name="distinct_channels" select="$ROOT_A/ES_PRODUCT[generate-id() = generate-id(key('channels',p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name)[1])]" />
                <xsl:variable name="distinct_years" select="$ROOT_A/ES_PRODUCT[generate-id() = generate-id(key('year',@year)[1])]" />
                <xsl:for-each select="$distinct_channels">
                    <xsl:variable name="thisChannel" select="p_product_restrictions/ES_PRODUCTRESTRICTION/pr_channel/ESP_CHANNEL/@name"/>
                    <xsl:variable name="distinct_producers" select="key('channels', $thisChannel)[generate-id() = generate-id(key('producers_by_channel',concat($thisChannel, '|', trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname))[1])]" />
                    <Row ss:Height="15.75">
                        <Cell ss:StyleID="s75">
                            <Data ss:Type="String">
                                <xsl:value-of select="$thisChannel"/>
                            </Data>
                        </Cell>
                        <xsl:for-each select="$distinct_producers">
                            <xsl:variable name="thisProducer" select="trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname"/>

                                <Cell ss:StyleID="s75">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisProducer"/>
                                    </Data>
                                </Cell>
                        </xsl:for-each>
                    </Row>

                    <xsl:for-each select="$distinct_years">
                        <xsl:variable name="thisYear" select="@year"/>

                            <Row ss:Height="15.75">
                                <Cell ss:StyleID="s74">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$thisYear"/>
                                    </Data>
                                </Cell>
                                <xsl:for-each select="$distinct_producers">
                                    <xsl:variable name="thisProducer" select="trailerProject/wontrailerproject/producer/ES_PERSON/@pe_fullname"/>
                                        <Cell ss:StyleID="s74">
                                            <Data ss:Type="Number">
                                                <xsl:value-of select="count(key('full', concat($thisChannel, '|', $thisProducer, '|', $thisYear)))"/>
                                            </Data>
                                        </Cell>
                                </xsl:for-each>
                            </Row>
                    </xsl:for-each>
                </xsl:for-each>
            </Table>
            <!-- WorksheetOptions go here -->
        </Worksheet>
    </Workbook>
</xsl:template>
</xsl:stylesheet>

xsl:sort with preceding-sibling XSLT 1.0 XSL-FO muenchian xsl:key


Tag : sorting , By : msugar
Date : March 29 2020, 07:55 AM
should help you out If node-set() isn't working, then you need to do the sorting again just to get the previous item:
<xsl:key name="all" match="catalogSeqNumber" use="true()" />

<xsl:template name="SortParts">
  <xsl:apply-templates
      select="catalogSeqNumber[key('kfigNo', @figureNumber)]">
      <xsl:sort select="itemSeqNumber/partRef/@partNumberValue"/>
      <xsl:sort select="@figureNumber"/>
      <xsl:sort select="@item"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="catalogSeqNumber">
  <xsl:variable
      name="figNo"
      select="concat(@figureNumber,@figureNumberVariant)"/>
  <xsl:variable name="current-position" select="position()"/>
  <xsl:variable name="prfigNo">
    <xsl:for-each select="key('all', true())">
      <xsl:sort select="itemSeqNumber/partRef/@partNumberValue"/>
      <xsl:sort select="@figureNumber"/>
      <xsl:sort select="@item"/>
      <xsl:if test="position() = $current-position - 1">
        <xsl:value-of select="concat(@figureNumber,@figureNumberVariant)" />
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
  <fo:table-row>
    <fo:table-cell padding="3pt">
      <fo:block>
        <xsl:value-of
            select="itemSeqNumber/partRef/@partNumberValue"/>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell padding="3pt">
      <fo:block>
        <xsl:if test="$figNo">
          <xsl:text> </xsl:text>
          <xsl:value-of select="$figNo"/>
          <xsl:text> </xsl:text>
          <xsl:value-of select="$prfigNo"/>
        </xsl:if>
      </fo:block> 
    </fo:table-cell>
    <fo:table-cell padding="3pt">
      <fo:block>
        <xsl:value-of select="concat(@item,@itemVariant)"/>
      </fo:block>
    </fo:table-cell>
    <fo:table-cell padding="3pt">
      <fo:block>
        <xsl:value-of
            select="itemSeqNumber/quantityPerNextHigherAssy"/>
      </fo:block>
    </fo:table-cell>
  </fo:table-row>
</xsl:template>

XSLT MUENCHIAN METHOD for all the nodes


Tag : xslt , By : DarrenBeck
Date : March 29 2020, 07:55 AM
it fixes the issue If you want to get the unique value attributes by product, you will have to make a reference to the product part of the key
 <xsl:key name="values" match="@value" use="concat(generate-id(ancestor::Product), '|', .)" />
<xsl:for-each select=".//@value[generate-id() = generate-id(key('values', concat($id, '|', .))[1])]">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:key name="values" match="@value" use="concat(generate-id(ancestor::Product), '|', .)" />

  <xsl:template match="Product">
    <xsl:variable name="id" select="generate-id()" />
    <xsl:copy>
        <xsl:for-each select=".//@value[generate-id() = generate-id(key('values', concat($id, '|', .))[1])]">
            <values><xsl:value-of select="." /></values>
        </xsl:for-each>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
<xsl:for-each-group select=".//@value" group-by=".">
<xsl:for-each select="distinct-values(.//@value)">
Related Posts Related QUESTIONS :
  • unexpected token while reading xml to string in JSR223 sampler
  • Concatenate XML in SQL stored Procedure
  • XSL - Only getting data from one node in my XML
  • XML schema - No matching global declaration available for the validation root
  • How to duplicate an entire XML Node and insert it in the XML data using TSQL
  • Groovy to get node values from XML in SoapUI response
  • XmlEntries to single CosmosDB entries with Azure Function
  • Create child in XML within node by attribute name
  • How to search and edit an xml tag that matches a condtion using xmlstarlet
  • Google App Script XmlService addNamespace method is adding blank XML namespaces to child elements
  • Convert CSV to XML using Mule 4
  • Why is xsl:when and xsl:value-of not working here?
  • Problem to generate HTML page via XML and XSL (i18n context)
  • How can I pass info about a referring page in a B2C claim
  • TSQL: How to get a UNION result from two tables with XML information in T1.Field_A and nvarchar in T2.Field_A
  • Make different changes in each line of bash script based on a list file
  • Xslt 1.0 if element value from a node is true then grab the value of another element from the same node
  • Is it possible to include one select in another?
  • Split XML file into multiple files using XSLT
  • simpletype is invalid in this context
  • XSLT select all elements except 3 and put them in a new field
  • Failed to parse a schema xsd
  • Converting local types to global types in XML Schema
  • Search and return tag name based off attribute within the tag xml bash
  • How to proper add xml namespace in an xmlstarlet update command when along used with XPath
  • XML Schema - Element attribute with different datatypes (need a simple typ definition)
  • Why is this xslt copy-of example not returning expected result
  • "not a schema document" when validating XML schema with notepad++ XML tools
  • Getting values from xml file
  • ElementTree find returns None even without xmlns
  • Concatenate parent attributes recursively - And preserve element data
  • Powershell- Convert Complex XML to CSV
  • How to parse .XML data for unsecured networks
  • Extract specific fields from xml file
  • Concatenate parent attributes recursively
  • Is there a way to transform multiple numeric xml values and pass on the sum total?
  • What is the difference between 'xsl:copy-of' and 'xsl:sequence'?
  • How to resolve XInclude instructions in a XML file from command line with XSLT 3.0
  • Extract an specific node from XML file in VB.NET
  • XSD to validate a list of 1 to 4 specific characters
  • XSLT 1.0 - Use delimiter to split fields inside for-each loop
  • Delete a xml child element from a selected node using FLWOR
  • XSLT. Copy node and modify child with name matches variable value
  • Remove SOAP Envelope namespace from XML
  • XPath for attribute in parent not containing a specific character?
  • Remove nodes satisfying condition and then the parent if empty
  • Get data from XML elements as a table using Powershell
  • Rename XML tags using XSLT
  • Retrieve Element Tag Value XML Using Bash
  • why "<" , ">" , " and ' are shown in this xml example
  • XSLT: Why aren't my variables not incrementing correctly with position()?
  • Flutter remove spaces and line breaks in string between character pattern
  • Parent xml in sql query, xpath
  • XSLT: Omit last newline in output
  • Making a XML-built component evoke a non-interface code
  • Extract XML content using Action parallely
  • Is there a way to specify the lowest ancestor in XPath?
  • XSLT sequentially retrieving attribute value from XML file
  • How to check whether a xml element value is "null" using XSLT?
  • Spring batch extract xml record from database
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com