[Home] [By Thread] [By Date] [Recent Entries]
On 08.04.2010 17:50, Michael M|ller-Hillebrand wrote:
Am 08.04.2010 um 16:09 schrieb Michael Kay: Here's a modified XSLT that will complain about <o/> if you include it inconsistently (<seq><k/><f/><z/><o/></seq>): --------------------------------------- <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="URN:my" version="2.0" > <xsl:output
method="xml"
indent="yes"
/>
<xsl:template match="foo">
<xsl:copy>
<xsl:for-each-group select="seq/*" group-by="name(.)" >
<xsl:sort select="my:sortkey(., ())"/>
<xsl:element name="{current-grouping-key()}" />
</xsl:for-each-group>
</xsl:copy>
</xsl:template><xsl:function name="my:sortkey" as="xs:integer"> <xsl:param name="input" as="element(*)" /> <xsl:param name="previously-seen" as="xs:string*" /> <xsl:if test="name($input) = $previously-seen"> <xsl:message terminate="yes">Element <xsl:value-of select="name($input)"/> doesn't seem to occur at an deterministic position. </xsl:message> </xsl:if> <xsl:variable name="preceding-siblings" select="$input/../../seq/*[name() = name($input)]/preceding-sibling::*[1]" as="element(*)*" /> <xsl:variable name="seen" select="distinct-values(($previously-seen, name($input)))" /> <xsl:sequence select="(max(for $ps in $preceding-siblings return my:sortkey($ps, $seen)) + 1, 1)[1]"/> </xsl:function> </xsl:stylesheet> --------------------------------------- No time to explain how it works now. Later! Gerrit
|

Cart



