Rendering nodes in different order
Posted: Thu Dec 03, 2020 8:17 pm
Hello.
That's my source XML
Sometimes I need title to be displayed before status. That's my code using Oxygen 21.1
The problem is that <title> is rendered twice both before and after status. How do I fix that?
Output I get :
Title status
Title
some node
Output I want:
Title status
some node
That's my source XML
Code: Select all
<root>
<status> status </status>
<content>
<Description>
<title>Title </title>
<some_node>some node </some_node>
</Description>
</content>
</root>
Code: Select all
<xsl:stylesheet>
<xsl:param name="TitleOnTop" select="'true'"/>
<xsl:template match="root">
<xsl:if test="$TitleOnTop='true'">
<xsl:apply-templates select="//title[1]"></xsl:apply-templates>
</xsl:if>
<xsl:choose>
<xsl:when test="$TitleOnTop='true'">
<xsl:apply-templates select="*[not(self::title)]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="title">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>:
Output I get :
Title status
Title
some node
Output I want:
Title status
some node