Relaxng refAtt resolver.xslt
Jump to navigation
Jump to search
This stylesheet reads in a TEI P4 RELAX NG schema (XML syntax) — such a thing would be created by converting a flat TEI P4 DTD with a tool like trang — and writes out the same schema with references to attribute lists resolved.
This is not generally a useful thing to do, but makes it easier to process the schema further, e.g. with GenerateDefaultAttributeRemover.xslt.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://relaxng.org/ns/structure/1.0" xmlns:rng="http://relaxng.org/ns/structure/1.0"> <!-- Reads in a TEI RELAX NG (XML syntax) file, and writes out the same with --> <!-- references to attribute list definitions resolved --> <!-- Minor tweaks 2008-11-19 to reduce verbosity of matches --> <!-- First working version 2008-03-16 (I don't know why, but it wouldn't work --> <!-- witout explicit namespace prefixes; i.e., unqualified names even with --> <!-- default NS decl above did not work.) --> <!-- Conceived and started 2008-03-15 --> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="rng:define[starts-with(@name,'attlist.')]"> <xsl:comment>deleted define <xsl:value-of select="@name"/></xsl:comment> </xsl:template> <xsl:template match="rng:define" mode="referred"> <xsl:apply-templates/> </xsl:template> <xsl:template match="rng:ref[starts-with(@name,'attlist.')]"> <xsl:comment>resolved define <xsl:value-of select="@name"/></xsl:comment> <xsl:variable name="name" select="@name"/> <xsl:apply-templates mode="referred" select="//rng:define[@name=$name]"/> </xsl:template> </xsl:stylesheet>