>> My question is, has someone already generated an XSLT that would
>> abbreviate tags in this kind of way AND generate the corresponding
>> "decoder" XSLT which would reconstitute the original. I have ideas
>> about how to do it using a procedural language, but I would like to do
>> it entirely with XSL transforms if I can.
>>
>> The only part that I don't really know how to do is to automatically
>> generate short, unique abbreviations for each of the tags. I *could*
>> specify them all manually once, but I'd prefer an automatic solution to
>> simplify maintenance.
>
> this will generate the following output:
>
> <name-mapping>
> <name s="a">original-xml-fragment</name>
> <name s="b">very-long-and-verbose-tag</name>
> <name s="c">name</name>
> <name s="d">more-information-is-stored-here</name>
> <name s="e">valuable-additional-information</name>
> </name-mapping>
>
Hi, again
given that it is allowed to use two steps of tranformation, you can do this:
Unleash the above stylesheet on the verbose XML and let it output to a file named 'name-map.xml'.
When you apply the following stylesheet, the verbose XML will be reduced.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl

utput method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:variable name="name" select="local-name()"/>
<xsl:element name="{document('name-map.xml')//name[.=$name]/@s}">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:variable name="name" select="local-name()"/>
<xsl:attribute name="{document('name-map.xml')//name[.=$name]/@s}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
The reduced form will look like this:
<a>
<b c="Long tag 1">
<d c="stuff 1"/>
</b>
<b c="Long tag 2">
<d c="stuff 2"/>
<e c="foo"/>
</b>
</a>
And this stylesheet will expand it again to the original verbose form:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl

utput method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:variable name="name" select="local-name()"/>
<xsl:element name="{document('name-map.xml')//name[@s=$name]}">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:variable name="name" select="local-name()"/>
<xsl:attribute name="{document('name-map.xml')//name[@s=$name]}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
I hope this is useful.
regards,
--
Joris Gillis (
http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum