Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using xsl:variable with XSLT-1

Snippet:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:msa="http://www.publictalksoftware.co.uk/msa">
    <xsl:output method="html" indent="yes" version="4.01"
      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
      doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
    <xsl:param name="CSSFile1"></xsl:param>
    <xsl:variable name="DutyHistory" select="document('DutyAssignHistory.XML')"/>
    <xsl:variable name="LabelsInfo" select="document('LabelsInfo.XML')"/>
    <xsl:template match="/">

Does it matter if the xsl:variable lines go before or after the xsl:param line? I moved them inside Visual Studio and saw no warnings but I wondered if there was some underlying expectation of which order to have these in the XSL file.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The relative order in which variables and parameters are defined makes no difference. The only thing that matters is that they are in scope at the point in the stylesheet where you want to use them.

You could even do:

<xsl:variable name="b" select="2 + $a"/>
<xsl:param name="a" select="3"/>

and the result of

<xsl:value-of select="$b"/> 

will be 5 in any region of the stylesheet tree within which these bindings are visible – see: https://www.w3.org/TR/1999/REC-xslt-19991116/#variables

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading