Tempore 10:44:00, die Saturday 15 January 2005 AD, hinc in foro {comp.text.xml} scripsit Richard Rudie <rsquared@sidbushes.mislead.com>:[color=blue]
> I opened it in a text editor, and found a bunch of poorly-designed XML
> structure---or so it seems to me, as I wouldn't be posting a question
> otherwise. The elements are arranged like so:[/color]
Hi,
I wouldn't label this XML as poorly-designed (that's my opinion) , but If you prefer the '<item key="..." data="..."/>' structure, you can use this stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//key[not(parent::dict)]"/>
</xsl:template>
<xsl:template match="key">
<xsl:apply-templates select="following-sibling::dict[1]"/>
</xsl:template>
<xsl:template match="dict">
<xsl:copy>
<xsl:attribute name="key">
<xsl:value-of select="preceding-sibling::key[1]"/>
</xsl:attribute>
<xsl:apply-templates select="key" mode="collect"/>
</xsl:copy>
</xsl:template>
<xsl:template match="key" mode="collect">
<item key="{.}" data="{following-sibling::*[1]}"/>
</xsl:template>
</xsl:stylesheet>
A html track table might be constructed from your original XML with this kind of XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<table>
<tr><th>Key</th><xsl:apply-templates select="//dict[1]/key" mode="litteral"/></tr>
<xsl:apply-templates select="//key[not(parent::dict)]"/>
</table>
</xsl:template>
<xsl:template match="key">
<tr>
<td><xsl:value-of select="."/></td>
<xsl:apply-templates select="following-sibling::dict[1]"/>
</tr>
</xsl:template>
<xsl:template match="dict">
<xsl:apply-templates select="key" mode="collect"/>
</xsl:template>
<xsl:template match="key" mode="collect">
<td><xsl:value-of select="following-sibling::*[1]"/></td>
</xsl:template>
<xsl:template match="key" mode="litteral">
<th><xsl:value-of select="."/></th>
</xsl:template>
</xsl:stylesheet>
The same table might be constructed with the 'cleaned up' XML as input with this stylesheet;
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<table>
<tr><th>Key</th><xsl:apply-templates select="//dict[1]/item/@key"/></tr>
<xsl:apply-templates select="//dict"/>
</table>
</xsl:template>
<xsl:template match="dict">
<tr>
<td><xsl:value-of select="@key"/></td>
<xsl:apply-templates select="item"/>
</tr>
</xsl:template>
<xsl:template match="item">
<td><xsl:value-of select="@data"/></td>
</xsl:template>
<xsl:template match="@key">
<th><xsl:value-of select="."/></th>
</xsl:template>
</xsl:stylesheet>
regards,
--
Joris Gillis (
http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Deserta faciunt et innovationem appelant