XSLT using a variable globally within the template

I have an XSLT object. I have a template function that parses a file path in the XML and adds an extension to the file name if its not present. However, I have no idea how to get the variable ($addingExtension) to be a global variable that I can reference throughout the template or at least in the template. Can anyone help me please? Thank you!

The XML is as follows:

<?xml version="1.0" encoding="UTF-8"?> /path1/path2/path3/amd xml [GettingExtension_Post.xsl|attachment](upload://dyLKwHgvcirQZrTXyYRTOcX22UW.xsl) (4.71 KB)

Variables in XSLT work a lot differently from the way variables work in procedural languages. To create a top-level variable, which can be accessed in any template, you code an xsl:variable element as a direct child of the xsl:stylesheet element, not within any xsl:template element.

If you really need to evaluate the expression for your variable’s value within a template and access it in other templates, you need to pass it as a parameter in your xsl:call-template or xsl:apply-templates elements.

I hope that wasn’t too opaque.

Thank you for responding. I think I understand what you are saying and I have used variables in other templates but for some reason, I just don’t quite get why its doing what’s its doing. If you look <xsl:copy-of select="$comeon/>, it for some reason returns the <xsl:value-of select="$gettingNameOfFile"/> and <xsl:value-of select="$addingExtension"/> in back in the output (i.e. I can see it print out in the HTML). The moment I take out <xsl:copy-of select="$comeon"/>, nothing returns. This to be was really bizarre-perhaps you can tell me wth(eck). Also, all I need it to be able to pass in <xsl:value-of select="$addingExtension"/> into another template to build the href so <xsl:attribute name=“href”><xsl:value-of select="$addingExtension"/></xsl:attribute>. Can you tell me how I would do this in the code? I have been banging my head against the wall for hours. Thank you so much!

Hey Curtis-
I think I got it. But I would still be curious to know if you were going to suggest the same thing or a better way. Thanks!

Since I couldn’t really figure out what you were trying to do with the variable in the short amount of time I had to look at your stylesheet, I didn’t have any better advice to give.