Re: [xsl] grouping probs

Subject: Re: [xsl] grouping probs
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 16 Sep 2002 17:49:06 +0100
Hi Laura,

> The reason why i want to generalize is because i have around 100
> elements in my source XML , which have to be unique..as i described.

That's a monster markup language!

> so i cant actually go around naming each and every element.so i thot i shud 
> have a generalized way of doing this.
> Ok.. taking your advice, I want to try the XSLT2 way..as i agree that the 
> two pass method is quite tedious..
> I however have got no clue about XSLT2.. How do i start it? what jar files 
> do i need? I am using XALAN right now. and editor is XSelerator.

I *was* recommending XSLT 2.0 on the basis of wanting a less tedious
way of finding duplicate values than using the Muenchian method. I was
thinking that you could use xsl:for-each-group to identify the
distinct values for each element, but this would still require you to
specify the way in which you determined identity for each of your
element types, and with 100 element types I can see why you wouldn't
want to do that. However, you can use the deep-equal() function in
XPath 2.0 to do what you want...

The only processor that supports XSLT 2.0 right now is Saxon (version
7.2 currently). You can get it from http://saxon.sourceforge.net. I
am not sure whether it supports deep-equal() yet, but you could
try something like:

<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()" />
  </xsl:copy>
</xsl:template>

<xsl:template match="*">
  <xsl:if test="not(preceding-sibling::*[deep-equal(., current())])">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:if>
</xsl:template>

If you don't want to use Saxon or Saxon doesn't support deep-equal(),
the algorithm for the deep-equal() function is available at

  http://www.w3.org/TR/xquery-operators/#func-deep-equal

You should be able to create equivalent XSLT templates; if you need
help with that let us know.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread