سؤال

أقول هذا بالنظر إلى ملف xml

<root>
    <node>x</node>
    <node>y</node>
    <node>a</node>
</root>

وأريد التالية ليتم عرضها

ayx

استخدام شيء مشابه

<xsl:template match="/">
    <xsl:apply-templates select="root/node"/>
</xsl:template>
<xsl:template match="node">
    <xsl:value-of select="."/>
</xsl:template>
هل كانت مفيدة؟

المحلول

من السهل!

<xsl:template match="/">
    <xsl:apply-templates select="root/node">
        <xsl:sort select="position()" data-type="number" order="descending"/>
    </xsl:apply-templates>
</xsl:template>

<xsl:template match="node">
    <xsl:value-of select="."/>
</xsl:template>

نصائح أخرى

يمكنك القيام بذلك باستخدام xsl:النوع.من المهم تعيين نوع البيانات="عدد" لأن آخر موقف سيتم فرز كسلسلة نهاية لذلك, 10 عقدة أن قه النظر فيها قبل 2nd واحد.

<xsl:template match="/">
    <xsl:apply-templates select="root/node">
        <xsl:sort 
            select="position()" 
            order="descending" 
            data-type="number"/>
    </xsl:apply-templates>
</xsl:template>
<xsl:template match="node">
    <xsl:value-of select="."/>
</xsl:template>
<xsl:template match="/">
        <xsl:apply-templates select="root/node[3]"/>
        <xsl:apply-templates select="root/node[2]"/>
        <xsl:apply-templates select="root/node[1]"/>
    </xsl:template>
    <xsl:template match="node">
        <xsl:value-of select="."/>
    </xsl:template>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top