Philipp Lenssen wrote:
> I have this XML file which I would like to XSLT-sort based on the
> string contained within the item-children elements using basic MSXML
> (no recent version of IIS, so it might be an outdated MSXML -- pretty
> sure not MSXML4, though tips on how to do it with that are appreciated
> too):
>
> ----------- Translation Dictionary (German) ----
> <?xml version="1.0" encoding="iso-8859-1"?>
> <items>
> <item id="4">
> <Deutsch>Registrieren</Deutsch>
> <Englisch-GB>Register</Englisch-GB>
> <Englisch-US>Register</Englisch-US>
> <Französisch>S'enregistrer</Französisch>
> <Italienisch>Registra</Italienisch>
> <Spanisch>Darse de alta</Spanisch>
> <Portugiesisch></Portugiesisch>
> <Niederländisch>Registreren</Niederländisch>
> <Kommentar></Kommentar>
> </item>
> <item id="5">
> <Deutsch>Login</Deutsch>
> <Englisch-GB>Login</Englisch-GB>
> <Englisch-US>Login</Englisch-US>
> <Französisch>Login</Französisch>
> <Italienisch>Login</Italienisch>
> <Spanisch>Inicio de sesión</Spanisch>
> <Portugiesisch></Portugiesisch>
> <Niederländisch>Login</Niederländisch>
> <Kommentar></Kommentar>
> </item>
> <!-- ... and many more item-elements -->
> </items>
Assuming you want to copy all nodes while ordering the children of
<item> by their content the following is an XSLT 1.0 stylesheet that
does that:
<?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" encoding="ISO-8859-1" />
<xsl:template match="item">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="*">
<xsl:sort data-type="text" order="ascending" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The result of the example file transformed with Xalan is
<?xml version="1.0" encoding="ISO-8859-1"?>
<items>
<item id="4">
<Portugiesisch/>
<Kommentar/>
<Spanisch>Darse de alta</Spanisch>
<Englisch-GB>Register</Englisch-GB>
<Englisch-US>Register</Englisch-US>
<Italienisch>Registra</Italienisch>
<Niederländisch>Registreren</Niederländisch>
<Deutsch>Registrieren</Deutsch>
<Französisch>S'enregistrer</Französisch>
</item>
<item id="5">
<Portugiesisch/>
<Kommentar/>
<Spanisch>Inicio de sesión</Spanisch>
<Deutsch>Login</Deutsch>
<Englisch-GB>Login</Englisch-GB>
<Englisch-US>Login</Englisch-US>
<Französisch>Login</Französisch>
<Italienisch>Login</Italienisch>
<Niederländisch>Login</Niederländisch>
</item>
<!-- ... and many more item-elements -->
</items>
As for MSXML, as far as I know MSXML 3.0 is the first to support XSLT
1.0 (which is indentified by the namespace URI
http://www.w3.org/1999/XSL/Transform). Earlier versions only support
some working draft (WD) with a different namespace and different
elements and semantics. I stronly suggest to get your ISP to install at
least MSXML 3.0 if you want to do XSLT 1.0 transformations.
--
Martin Honnen
http://JavaScript.FAQTs.com/