I have an xml file like this one: receipt.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xml" href="receipt.xslt"?>
<printedslip>
<pos>
<posno>11546546</posno>
</pos>
<store>
<storeno>1</storeno>
<storename>Store 01</storename>
<orgno>001</orgno>
<postalcode>550</postalcode>
</store>
<cashier>
<userno>1</userno>
<name>Sara</name>
</cashier>
<headertext>Receipt Profile Header</headertext>
</printedslip>
and an xslt file: receipt.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="params.xslt"/>
<xsl:include href="store.xslt"/>
<xsl:include href="headergroup.xslt"/>
<xsl:output method="text" />
<xsl:strip-space elements="*"/>
<xsl:template match="store">
<xsl:call-template name="store">
<xsl:with-param name="value" select="store"/>
<xsl:with-param name="store_no" select="$store_no"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="headertext">
<xsl:call-template name="receiptheader">
<xsl:with-param name="value" select="headertext"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="cashier">
<xsl:call-template name="cashier">
<xsl:with-param name="value" select="cashier"/>
<xsl:with-param name="cashier" select="$cashier"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
I expect to receive the output text, formed in the order in which the templates are added in the XSLT file. Instead I receive first the store information, cashier and header text, in the order the nodes appear in the XML file. I want to have the order from XSLT file: store, header text, cashier.
Is there a solution for this?
Add a template that matches the printedslip and then you can define in which order the child elements should be called:
Otherwise the order depends on the input XML (store, cashier, headertext). The order of the templates within the XSLT do not have an influence on the order of the elements in printedslip.
In general, a XSLT processor is running through all elements in the Input XML from top to bottom – so if you don’t want that order – you need to tell the processor that (in the xslt).