XSLT Sorting - como classificar xnns childnodes dentro de um nó pai com um atributo

O que começou como uma coisa simples acabou sendo bastante problemático para o noob do XSLT.

Tentando classificar childnodes / descendentes, mas depois de adicionar um atributo ao seu nó pai, recebo um erro ao depurar no VS2010:

"Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added."

Suponha que eu tenha este XML simples:

<posts>
    <year value="2013">
        <post postid="10030" postmonth="1">
            <othernode></othernode>
            <othernode2></othernode2>
        </post>
        <post postid="10040" postmonth="2">
            <othernode></othernode>
            <othernode2></othernode2>
        </post>
        <post postid="10050" postmonth="3">
             <othernode></othernode>
             <othernode2></othernode2>
        </post>
    </year>
    <year value="2012">
        <post postid="10010" postmonth="1">
            <othernode></othernode>
            <othernode2></othernode2>
        </post>
        <post postid="10015" postmonth="2">
            <othernode></othernode>
            <othernode2></othernode2>
        </post>
        <post postid="10020" postmonth="3">
             <othernode></othernode>
             <othernode2></othernode2>
        </post>
    </year>
</posts>

Eu passo um XPATH para um xmldatasource para recuperar o relevante<year> nó, por exemplo 2013. Então eu preciso classificar o seu filho<post> nós descendo usando o postid, então para<year value=2013>, postid = 10050 apareceria primeiro quando renderizado.

Então, para ser claro: estou interessado apenas em classificar dentro de um<year> nó.

Antes de dividir os nós em nós separados (por exemplo, xml era / posts / post), o seguinte XSLT funcionava:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()">
                <xsl:sort select="@postid" data-type="text" order="descending"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Agora o xmldatasource está vazio durante a execução devido ao erro acima. Se eu passar ascendendo na ordem, o mesmo xml é retornado obviamente (sem transformação)

Pergunta: como atualizar o XSLT acima (ou novo) para acomodar o atributo do nó pai (<year value="">) Através de pesquisa, uma resposta disse: "Eu preciso adicionar criação de atributos antes da criação do elemento". Isso faz sentido como assistir o depurador, os childnodes são formados em ordem desc, mas a tag de ano está faltando seu atributo. Mas eu não tenho a menor ideia sobre o XSLT. Não é possível ver isso sendo muito complicado, mas simplesmente não conhece o idioma.

Qualquer ajuda, muito apreciada. obrigado

questionAnswers(2)

yourAnswerToTheQuestion