another newcomer to xslt here. I have a problem similar to this one - Applying Muenchian grouping for a simple XML with XSLT - but complicated by an extra layer of nodes.
I have this XML...
<ALLDATA>
<THIS>
<ID>datum 1</ID>
<DATA>datarecord1</DATA>
<RELATIONSHIPS>
<rel>
<relid>rd1</relid>
<reldata>something</reldata>
</rel>
</RELATIONSHIPS>
</THIS>
<THIS>
<ID>datum 1</ID>
<DATA>datarecord1</DATA>
<RELATIONSHIPS>
<rel>
<relid>rd2</relid>
<reldata>other</reldata>
</rel>
</RELATIONSHIPS>
</THIS>
<THIS>
<ID>rd1</ID>
<DATA>relrecord1</DATA>
<RELATIONSHIPS/>
</THIS>
<THIS>
<ID>rd2</ID>
<DATA>relrecord2</DATA>
<RELATIONSHIPS/>
</THIS>
</ALLDATA>
... and would like to convert it to ...
<ALLDATA>
<THIS>
<ID>datum 1</ID>
<DATA>datarecord1</DATA>
<RELATIONSHIPS>
<rel>
<relid>rd1</relid>
<reldata>something</reldata>
</rel>
<rel>
<relid>rd2</relid>
<reldata>other</reldata>
</rel>
</RELATIONSHIPS>
</THIS>
<THIS>
<ID>rd1</ID>
<DATA>relrecord1</DATA>
<RELATIONSHIPS/>
</THIS>
<THIS>
<ID>rd2</ID>
<DATA>relrecord2</DATA>
<RELATIONSHIPS/>
</THIS>
</ALLDATA>
The xslt (1.0) I'm using is obviously way off base so was hoping someone with more knowledge (hi!) could help put me right :)
Here is the useless xslt...
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="krel" match="THIS" use="ID"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="appex_user/node">
<xsl:copy>
<xsl:apply-templates select="THIS[generate-id() = generate-id(key('krel', ID)[1])]" mode="group"/>
</xsl:copy>
</xsl:template>
<xsl:template match="THIS/RELATIONSHIPS" mode="group">
<xsl:copy>
<xsl:copy-of select="RELATIONSHIPS/rel"/>
<xsl:apply-templates select="key('krel', ID)"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Actually - I've tried all sorts of combinations to no avail.