How to group in XSLT using Muenchian Method?
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>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
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
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)">
|