sorting grouping data
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2
- Joined: Fri Dec 01, 2006 2:06 pm
sorting grouping data
Hi!
im havin XML:
<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<item id="i1" catalog="s1" subcatalog="u1">561</item>
<item id="i10" catalog="s3" subcatalog="u4">15</item>
<item id="i22" catalog="s2" subcatalog="u2">1234</item> etc
<catalog id="s1">catalog 1</catalog>
<catalog id="s2">catalog 2</catalog>
<catalog id="s3">catalog 3</catalog>
<subcatalog id="u1">Subcatalog 1</subcatalog>
<subcatalogid="u2">Subcatalog 2</subcatalog> etc
</data>
by meas of 2-level grouping (using keys) shoul look as follows:
catalog 1
Subcatalog 1
ID Value
id1 value1
...
...
catalog 2
Subcatalog 1
ID Value
id1 value1...
....
etc
my xsl:
...
<xsl:variable name="Sort1" select="@catalog"/>
<xsl:variable name="Sort2" select="@subcatalog"/>
<xsl:key name="Sector" match="item" use="@catalog"/>
<xsl:key name="Subsector" match="item" use="concat(@catalog, ' ',@subcatalog)"/>
<xsl:template match="data" >
<xsl:variable name="Sort11" select="key('Sector',substring-after($Sort1,'s'))"/>
<xsl:variable name="Sort22" select="key('Subsector',concat(substring-after($Sort1,'s'),' ',substring-after($Sort2,'u')))"/>
<xsl:for-each select="item[count(. | key('Sector', @catalog)[1]) = 1]">
<xsl:sort select="*[name()=$Sort11]" order="ascending" data-type="number"/>
<div>
<xsl:value-of select="//sector[@id=current()/@catalog]"/>
</div>
<xsl:variable name="Items" select="key('Sector', @catalog)" />
<xsl:for-each select="$Items[generate-id() =generate-id(key('Subsector',concat(@catalog,' ',@subcatalog))[1])]">
<xsl:sort select="*[name()=$Sort22]" order="ascending" data-type="number"/>
<xsl:value-of select="//subcatalog[@id=current()/@subcatalog]" />
<xsl:for-each select="key('Subcatalog',concat(@catalog,' ',@subcatalog))">
<div>
<xsl:value-of select="@id"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
</div>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
It groups but doesnt sort, i believe the problem is in syntax in sorting. Any ideas?
Tnx in advance
im havin XML:
<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<item id="i1" catalog="s1" subcatalog="u1">561</item>
<item id="i10" catalog="s3" subcatalog="u4">15</item>
<item id="i22" catalog="s2" subcatalog="u2">1234</item> etc
<catalog id="s1">catalog 1</catalog>
<catalog id="s2">catalog 2</catalog>
<catalog id="s3">catalog 3</catalog>
<subcatalog id="u1">Subcatalog 1</subcatalog>
<subcatalogid="u2">Subcatalog 2</subcatalog> etc
</data>
by meas of 2-level grouping (using keys) shoul look as follows:
catalog 1
Subcatalog 1
ID Value
id1 value1
...
...
catalog 2
Subcatalog 1
ID Value
id1 value1...
....
etc
my xsl:
...
<xsl:variable name="Sort1" select="@catalog"/>
<xsl:variable name="Sort2" select="@subcatalog"/>
<xsl:key name="Sector" match="item" use="@catalog"/>
<xsl:key name="Subsector" match="item" use="concat(@catalog, ' ',@subcatalog)"/>
<xsl:template match="data" >
<xsl:variable name="Sort11" select="key('Sector',substring-after($Sort1,'s'))"/>
<xsl:variable name="Sort22" select="key('Subsector',concat(substring-after($Sort1,'s'),' ',substring-after($Sort2,'u')))"/>
<xsl:for-each select="item[count(. | key('Sector', @catalog)[1]) = 1]">
<xsl:sort select="*[name()=$Sort11]" order="ascending" data-type="number"/>
<div>
<xsl:value-of select="//sector[@id=current()/@catalog]"/>
</div>
<xsl:variable name="Items" select="key('Sector', @catalog)" />
<xsl:for-each select="$Items[generate-id() =generate-id(key('Subsector',concat(@catalog,' ',@subcatalog))[1])]">
<xsl:sort select="*[name()=$Sort22]" order="ascending" data-type="number"/>
<xsl:value-of select="//subcatalog[@id=current()/@subcatalog]" />
<xsl:for-each select="key('Subcatalog',concat(@catalog,' ',@subcatalog))">
<div>
<xsl:value-of select="@id"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
</div>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
It groups but doesnt sort, i believe the problem is in syntax in sorting. Any ideas?
Tnx in advance

Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service