| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 6 |
version="1.0"> |
| 7 |
|
| 8 |
<xsl:output indent="yes" method="xml"/> |
| 9 |
|
| 10 |
|
| 11 |
<xsl:key name="k-macro" match="//*" use="@id"/> |
| 12 |
|
| 13 |
|
| 14 |
<xsl:template match="/ | @* | node()"> |
| 15 |
<xsl:choose> |
| 16 |
|
| 17 |
<xsl:when test="contains(name(.),'_id') and not(*)"> |
| 18 |
<xsl:if test="not(key('k-macro',.))"> |
| 19 |
<xsl:message>No such ID: <xsl:value-of select="."/></xsl:message> |
| 20 |
</xsl:if> |
| 21 |
|
| 22 |
<xsl:copy> |
| 23 |
<xsl:variable name="macro" select="key('k-macro',.)"/> |
| 24 |
|
| 25 |
<xsl:for-each select="$macro"> |
| 26 |
<xsl:copy> |
| 27 |
<xsl:apply-templates select="$macro/*"/> |
| 28 |
</xsl:copy> |
| 29 |
</xsl:for-each> |
| 30 |
</xsl:copy> |
| 31 |
</xsl:when> |
| 32 |
<xsl:when test="count(@id)"> |
| 33 |
|
| 34 |
</xsl:when> |
| 35 |
<xsl:otherwise> |
| 36 |
|
| 37 |
<xsl:copy> |
| 38 |
<xsl:apply-templates select="@* | node()" /> |
| 39 |
</xsl:copy> |
| 40 |
</xsl:otherwise> |
| 41 |
</xsl:choose> |
| 42 |
</xsl:template> |
| 43 |
|
| 44 |
</xsl:stylesheet> |