locked
xslt to sort only immediate parent node RRS feed

  • Question

  • User-1813746550 posted

    Below is the xslt iam using to sort only immediate parent of stock nodes. But it is sorting the complete xml.

    <xsl:output omit-xml-declaration="yes" indent="yes"/>

    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">

    <xsl:copy>

    <xsl:apply-templates select="node()|@*"/>

    </xsl:copy>

    </xsl:template>

    <xsl:template match="/Family/Grandparents">

    <xsl:copy>

    <xsl:apply-templates select="node()|@*">

    <xsl:sort select="stock/text()" data-type="number"/>

    </xsl:apply-templates>

    </xsl:copy>

    </xsl:template>

    </xsl:stylesheet>

     

    my xml:

    <?xml version="1.0" encoding="UTF-8"?>

    <Family>

    <num>5</num>

    <num>2</num>

    <Grandparents>

    <Check>6</Check>

    <Check>3</Check>

    <Parents>

    <fewnodes>8</fewnodes>

    <fewnodes>4</fewnodes>

    <Parent>

    <node>3</node>

    <node>1</node>

    <stock>5</Stock>

    </parent>

    <Parent>

    <node>7</node>

    <node>4</node>

    <stock>3</Stock>

    </parent>

    </Parents>

    </Grandparents>

    </Family>

     

    I want this as output:

    <Family>

    <num>5</num>

    <num>2</num>

    <Grandparents>

    <Check>6</Check>

    <Check>3</Check>

    <Parents>

    <fewnodes>8</fewnodes>

    <fewnodes>4</fewnodes>

    <Parent>

    <node>7</node>

    <node>4</node>

    <stock>3</stock>

    </Parent>

    <Parent>

    <node>3</node>

    <node>1</node>

    <stock>5</stock>

    </Parent>

    </Parents>

    </Grandparents>

    </Family>

    but my xslt is sorting parents and gransparents nodes also.

    please correct the xslt

    Wednesday, January 9, 2013 5:12 PM

All replies

  • User3866881 posted

    Hi,

    I just wanna know why:

    <node>3</node>

    <node>1</node>

    <stock>5</Stock>

    is after

    <node>7</node>

    <node>4</node>

    <stock>3</stock>

    ?

    What algorithm have you got?

    Friday, January 11, 2013 5:42 AM