xsl-list
[Top] [All Lists]

Re: [xsl] Ordering by child node attribute

2011-12-27 14:30:48
Hi,

start with all Class elements without a SuperClass attribute,
then use recursion using the SubClass attribut:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

  <xsl:template match="root">
    <root>
      <xsl:apply-templates select="Class[not(SuperClass)]" />
    </root>
  </xsl:template>

  <xsl:template match="Class">
    <xsl:copy-of select="."/>
    <xsl:apply-templates select="../Class[@code=current()/SubClass/@code]" />
  </xsl:template>

</xsl:stylesheet>

Kind regards,
Markus


----------
Von:    Gian Paolo Bernardini - TeleTu
Gesendet:       Dienstag, 27. Dezember 2011 14:40
An:     xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff:        [xsl] Ordering by child node attribute

Hi all,

I'd like to order an xml from this form:

<?xml version="1.0" encoding="UTF-8"?>
<root>
        <Class code="B" kind="component">
                <SubClass code="b1"/>
                <SubClass code="b2"/>
        </Class>
        <Class code="b1" kind="chapter">
                <SuperClass code="B"/>
                <SubClass code="b110-b139"/>
        </Class>
        <Class code="b2" kind="chapter">
                <SuperClass code="B"/>
                <SubClass code="b210-b229"/>
        </Class>
        <Class code="b110-b139" kind="block">
                <SuperClass code="b1"/>
                <SubClass code="b110"/>
        </Class>
        <Class code="b210-b229" kind="block">
                <SuperClass code="b2"/>
                <SubClass code="b210"/>
        </Class>
        <Class code="b110" kind="fourdigit">
                <SuperClass code="b110-b139"/>
        </Class>
        <Class code="b210" kind="fourdigit">
                <SuperClass code="b210-b229"/>
        </Class>
</root>

to this form:

<?xml version="1.0" encoding="UTF-8"?>
<root>
        <Class code="B" kind="component">
                <SubClass code="b1"/>
                <SubClass code="b2"/>
        </Class>
        <Class code="b1" kind="chapter">
                <SuperClass code="B"/>
                <SubClass code="b110-b139"/>
        </Class>
        <Class code="b110-b139" kind="block">
                <SuperClass code="b1"/>
                <SubClass code="b110"/>
        </Class>
        <Class code="b110" kind="fourdigit">
                <SuperClass code="b110-b139"/>
        </Class>
        <Class code="b2" kind="chapter">
                <SuperClass code="B"/>
                <SubClass code="b210-b229"/>
        </Class>
        <Class code="b210-b229" kind="block">
                <SuperClass code="b2"/>
                <SubClass code="b210"/>
        </Class>
        <Class code="b210" kind="fourdigit">
                <SuperClass code="b210-b229"/>
        </Class>
</root>

I can't use 'sort' or 'grouping-by' because it returns for example b110
before b110-b139, which is not what I'm searching for.
If anyone has an idea it would be glad :)
Thanks in advance and happy new year

PS. currently I'm using SaxonHE9-4-0-1J, sometimes Xalan. I've no
constraints on the XSL versions.



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>