2006-09-03 10:41:57 +00:00
<?xml version="1.0" encoding="UTF-8"?>
<!-- This stylesheet will:
2006-10-08 11:14:57 +00:00
- reorder, indent and normalize a comps file,
2006-09-03 10:41:57 +00:00
- merge duplicate groups and categories,
2006-10-08 11:14:57 +00:00
- warn about packages referenced by multiple groups,
- kill multiple references to the same package within a group,
2006-09-03 10:41:57 +00:00
Typical usage is:
2006-10-07 23:36:09 +00:00
$ xsltproc -o output-file comps-cleanup.xsl original-file
2006-09-03 10:41:57 +00:00
2006-10-08 11:14:57 +00:00
You can use the ‑ ‑ novalid xsltproc switch to kill the warning about
2006-09-03 10:41:57 +00:00
Fedora not installing the comps DTD anywhere xsltproc can find it.
However without DTD there is no way to check the files completely.
© Nicolas Mailhot <nim a t f e d o r a p r o j e c t d o t o r g > 2006 -->
2006-10-08 12:26:12 +00:00
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:exsl= "http://exslt.org/common" version= "1.0" extension-element-prefixes= "exsl" >
2006-09-03 10:41:57 +00:00
<xsl:strip-space elements= "*" />
<xsl:output method= "xml" indent= "yes" encoding= "UTF-8" doctype-system= "comps.dtd" doctype-public= "-//Red Hat, Inc.//DTD Comps info//EN" />
<xsl:key name= "unique-groups" match= "/comps/group" use= "id/text()" />
<xsl:key name= "unique-categories" match= "/comps/category" use= "id/text()" />
<xsl:key name= "packages-by-group" match= "/comps/group/packagelist/packagereq" use= "../../id/text()" />
<xsl:key name= "unique-package-entries" match= "/comps/group/packagelist/packagereq" use= "concat(../../id/text(),'/',text())" />
2006-10-08 16:34:58 +00:00
<xsl:key name= "unique-packages" match= "/comps/group/packagelist/packagereq[generate-id(.) = generate-id(key('unique-package-entries',concat(../../id/text(),'/',text()))[1])]" use= "text()" />
2006-09-03 10:41:57 +00:00
<xsl:key name= "groups-by-category" match= "/comps/category/grouplist/groupid" use= "../../id/text()" />
<xsl:key name= "unique-group-entries" match= "/comps/category/grouplist/groupid" use= "concat(../../id/text(),'/',text())" />
<xsl:variable name= "lcletters" > abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name= "ucletters" > ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
2006-10-08 12:26:12 +00:00
<xsl:variable name= "type-sort-order" >
<unknown />
<mandatory />
<conditional />
<default />
<optional />
</xsl:variable>
<xsl:variable name= "attribute-sort-order" >
<unknown />
<type />
<requires />
<basearch />
</xsl:variable>
2006-09-03 10:41:57 +00:00
<!-- Preserve most nodes -->
<xsl:template match= "*" priority= "0" >
2006-10-08 11:14:57 +00:00
<xsl:apply-templates select= "." mode= "normalize" />
</xsl:template>
<xsl:template match= "*" mode= "normalize" >
2006-10-08 09:04:25 +00:00
<!-- Group comments with the logically - following element -->
<xsl:apply-templates select= "preceding-sibling::node()[normalize-space()][1][self::comment()] " />
2006-09-03 10:41:57 +00:00
<xsl:copy >
2006-10-08 11:14:57 +00:00
<xsl:apply-templates select= "@*" >
2006-10-08 12:26:12 +00:00
<xsl:sort select= "count(exsl:node-set($attribute-sort-order)/*[name() = name(current())]/preceding-sibling::*)" data-type= "number" />
2006-10-08 11:14:57 +00:00
</xsl:apply-templates>
2006-10-08 09:04:25 +00:00
<xsl:apply-templates select= "*|text()" />
2006-09-03 10:41:57 +00:00
</xsl:copy>
</xsl:template>
2006-10-08 09:04:25 +00:00
<!-- Preserve attributes and text nodes -->
<xsl:template match= "comment()|text()" >
<xsl:apply-templates select= "preceding-sibling::node()[normalize-space()][1][self::comment()] " />
<xsl:copy />
</xsl:template>
<!-- Preserve attributes -->
<xsl:template match= "@*" >
2006-09-03 10:41:57 +00:00
<xsl:copy />
</xsl:template>
2006-10-08 12:43:46 +00:00
<!-- Sort groups by id, and categories by display order -->
2006-09-03 10:41:57 +00:00
<xsl:template match= "comps" priority= "1" >
2006-10-08 12:43:46 +00:00
<xsl:apply-templates select= "preceding-sibling::node()[normalize-space()][1][self::comment()] " />
2006-09-03 10:41:57 +00:00
<xsl:copy >
<xsl:apply-templates select= "group" >
<xsl:sort select= "translate(id/text(),$lcletters,$ucletters)" />
</xsl:apply-templates>
<xsl:apply-templates select= "category" >
<xsl:sort select= "display_order/text()" />
2006-10-08 12:43:46 +00:00
<xsl:sort select= "translate(id/text(),$lcletters,$ucletters)" />
2006-09-03 10:41:57 +00:00
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
2006-10-08 12:43:46 +00:00
<!-- Warn about empty groups -->
<xsl:template match= "group[count(key('packages-by-group',id/text()))=0]" priority= "2" >
<xsl:message > ☹☹☹ Empty group <xsl:value-of select= "concat(_name/text(),' (',id/text(),')')" /> !</xsl:message>
<xsl:apply-templates select= "." mode= "normalize" />
</xsl:template>
2006-09-03 10:41:57 +00:00
<!-- Warn about duplicate groups being merged -->
2006-10-08 12:43:46 +00:00
<xsl:template match= "group[generate-id(.) != generate-id(key('unique-groups',id/text())[1])]" priority= "3" >
2006-10-08 09:04:25 +00:00
<xsl:message > ☹☹ Duplicate group <xsl:value-of select= "concat(_name/text(),' (',id/text(),')')" /> will be merged.</xsl:message>
2006-09-03 10:41:57 +00:00
</xsl:template>
2006-10-08 12:43:46 +00:00
<!-- Warn about empty categories -->
<xsl:template match= "category[count(key('groups-by-category',id/text()))=0]" priority= "2" >
<xsl:message > ☹☹☹ Empty category <xsl:value-of select= "concat(_name/text(),' (',id/text(),')')" /> !</xsl:message>
<xsl:apply-templates select= "." mode= "normalize" />
</xsl:template>
2006-09-03 10:41:57 +00:00
<!-- Warn about duplicate categories being merged -->
2006-10-08 12:43:46 +00:00
<xsl:template match= "category[generate-id(.) != generate-id(key('unique-categories',id/text())[1])]" priority= "3" >
2006-10-08 09:04:25 +00:00
<xsl:message > ☹☹ Duplicate category <xsl:value-of select= "concat(_name/text(),' (',id/text(),')')" /> will be merged.</xsl:message>
2006-09-03 10:41:57 +00:00
</xsl:template>
<!-- Sort packages within a group by class then name -->
<xsl:template match= "packagelist" priority= "1" >
<xsl:copy >
2006-10-08 12:26:12 +00:00
<xsl:apply-templates select= "key('packages-by-group',../id/text())" >
2006-10-08 13:54:42 +00:00
<xsl:sort select= "count(exsl:node-set($type-sort-order)/*[name() = current()/@type]/preceding-sibling::*)" data-type= "number" />
2006-09-03 10:41:57 +00:00
<xsl:sort select= "translate(text(),$lcletters,$ucletters)" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- Sort groups within a category by name -->
<xsl:template match= "category/grouplist" priority= "1" >
<xsl:copy >
<xsl:apply-templates select= "key('groups-by-category',../id/text())" >
<xsl:sort select= "translate(text(),$lcletters,$ucletters)" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- Kill duplicate package entries -->
<xsl:template match= "packagereq[generate-id(.) != generate-id(key('unique-package-entries',concat(../../id/text(),'/',text()))[1])]" priority= "2" >
2006-10-07 23:36:09 +00:00
<xsl:message > ☹☹☹ Ignoring duplicate reference to <xsl:value-of select= "concat(@type,' package ',text())" /> in group <xsl:value-of select= "concat(../../_name/text(),' (',../../id/text(),')')" /> .</xsl:message>
2006-10-08 10:39:31 +00:00
<xsl:message > ⇒ Only its first reference (<xsl:value-of select= "key('unique-package-entries',concat(../../id/text(),'/',text()))[1]/@type" /> package) will be kept.</xsl:message>
2006-09-03 10:41:57 +00:00
</xsl:template>
<!-- Kill duplicate group entries -->
<xsl:template match= "category/grouplist/groupid[generate-id(.) != generate-id(key('unique-group-entries',concat(../../id/text(),'/',text()))[1])]" priority= "1" >
2006-10-08 09:04:25 +00:00
<xsl:message > ☹ Ignoring duplicate reference to group <xsl:value-of select= "text()" /> in category <xsl:value-of select= "concat(../../_name/text(),' (',../../id/text(),')')" /> .</xsl:message>
2006-09-03 10:41:57 +00:00
</xsl:template>
2007-11-26 21:23:31 +00:00
<!-- Warn about packages referenced several times
2006-10-08 16:48:05 +00:00
<xsl:template match= "packagereq[generate-id(.) = generate-id(key('unique-packages',text())[2])]" priority= "1" >
2006-10-08 09:44:18 +00:00
<xsl:variable name= "dupes" select= "key('unique-packages',text())" />
2006-10-08 14:05:02 +00:00
<xsl:message > ☹ Package <xsl:value-of select= "text()" /> is referenced in <xsl:value-of select= "count($dupes)" /> groups:</xsl:message>
2006-10-08 09:44:18 +00:00
<xsl:for-each select= "$dupes" >
2006-10-08 10:26:07 +00:00
<xsl:sort select= "translate(../../id/text(),$lcletters,$ucletters)" />
2006-10-08 09:04:25 +00:00
<xsl:message > ✓ <xsl:value-of select= "@type" /> package in group <xsl:value-of select= "concat(../../_name/text(),' (',../../id/text(),')')" /> </xsl:message>
2006-09-03 10:41:57 +00:00
</xsl:for-each>
2006-10-08 11:14:57 +00:00
<xsl:apply-templates select= "." mode= "normalize" />
2007-11-26 21:23:31 +00:00
</xsl:template> -->
2006-09-03 10:41:57 +00:00
</xsl:stylesheet>