Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL: Combining grouping and call-template
    primarykey
    data
    text
    <p>I've read with interest the techniques available on the web to extract a unique list of items from a XML file containing duplicates using XSL.</p> <p>These range into 2 categories: 1) The Muenchian method (example: <a href="http://www.jenitennison.com/xslt/grouping/" rel="nofollow noreferrer">http://www.jenitennison.com/xslt/grouping/</a>) 2) Or the previous-sibling look-up These both rely on an XPath expression to select the data to group by.</p> <p>However, in the XML file that I'm trying to work out, the data is not present "natively" in the XML file. I am using a xsl:template to compute some aggregated data from my elements. And I would like to group based on the aggregated data.</p> <p>For example I have:</p> <pre><code>&lt;filmsreview&gt; &lt;record&gt;&lt;data name='movie'&gt;Star Wars&lt;/data&gt;&lt;data name='ratings'&gt;John:Good, Mary:Good&lt;/data&gt;&lt;/record&gt; &lt;record&gt;&lt;data name='movie'&gt;Indiana Jones&lt;/data&gt;&lt;data name='ratings'&gt;John:Good, Mary:Bad, Helen:Average&lt;/data&gt;&lt;/record&gt; &lt;record&gt;&lt;data name='movie'&gt;Titanic&lt;/data&gt;&lt;data name='ratings'&gt;John:Bad, Helen:Good&lt;/data&gt;&lt;/record&gt; &lt;/filmsreview&gt; </code></pre> <p>I know that the structuration of data is not perfect and that by creating sub-elements I could do something easier, but I cannot change the data source easily, so let's take this as a challenge.</p> <p>And I would like to build a recap where I have John's distinct ratings: John's ratings: Good Bad</p> <p>I have a xsl:template that can take a record element and return John's rating for this record: Example:</p> <pre><code>&lt;xsl:template name="get_rating"&gt; &lt;xsl:param name="reviewer" /&gt; &lt;!-- I use some string manipulation, and xsl:value-of to return the review for John--&gt; &lt;/xsl:template&gt; </code></pre> <p>I can just call it under a xsl:for-each to get the exhaustive list of John's review. But I cannot combine this call with any of the methods to get unique values.</p> <p>Do I have to use an intermediary XSL to convert my XML file to a more structured way? Or can I do in a single step?</p> <p>Many thanks Gerard</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload