link xslt files - how to call a xslt variable from a different xslt file
Is there a way to declare an XSLT variable in one XSLT file, and call that variable in a different XSLT file?
I have a series of SQL database tables, all of which point to the same database. I would like to store the name o fthe database as a variable so that I can call the variable in each of my SQL query strings. This way, should we ever change from one database to another, I only have to change the value of my database name variable rather than going through every single XSLT file to change the database name.
Here's a snippet of what I'd like to do:
In one XSLT file, I want to store the name of my database:
<xsl:variable name = "dbName" select = "Web_Database" />
Then, in several XSLT files used throughout the website, I would like to replace "Web_Database" with $dbName:
<xsl:variable name = "variable_name" select="SQL:GetDataSet('$dbName', 'SELECT column_name FROM table_name', 'item')"/>
How do I transmit a variable from one XSLT file to another?
I guess it would be possible if you create one XSLT file holding the variable and include it in all the XSLT files that access the database.
On the other hand, I think a nicer solution would be to store the database name in a content node and read it from there.
Another option is to create your own XSLT helper method which fetches the database name from wherever (xml, web service, hardcoded, ..) although the former option is much easier :-)
As you've probably found out, you can't include/import an XSLT file that has a global variable/param with the same name as a global in the "master" XSLT file - the way you usually tackle this, is to define the variable globally in the master, and then in the included file(s), use a local variable in each template. Then use the <xsl:with-param /> instruction when calling/applying templates - this way, you've modularized the components and the templates don't depend on any outside stuff. TL;DR:
link xslt files - how to call a xslt variable from a different xslt file
Is there a way to declare an XSLT variable in one XSLT file, and call that variable in a different XSLT file?
I have a series of SQL database tables, all of which point to the same database. I would like to store the name o fthe database as a variable so that I can call the variable in each of my SQL query strings. This way, should we ever change from one database to another, I only have to change the value of my database name variable rather than going through every single XSLT file to change the database name.
Here's a snippet of what I'd like to do:
In one XSLT file, I want to store the name of my database:
Then, in several XSLT files used throughout the website, I would like to replace "Web_Database" with $dbName:
<xsl:variable name = "variable_name" select="SQL:GetDataSet('$dbName', 'SELECT column_name FROM table_name', 'item')"/>
How do I transmit a variable from one XSLT file to another?
Hi Luke,
I guess it would be possible if you create one XSLT file holding the variable and include it in all the XSLT files that access the database.
On the other hand, I think a nicer solution would be to store the database name in a content node and read it from there.
Another option is to create your own XSLT helper method which fetches the database name from wherever (xml, web service, hardcoded, ..) although the former option is much easier :-)
Grtz
L
Hi Luke,
As you've probably found out, you can't include/import an XSLT file that has a global variable/param with the same name as a global in the "master" XSLT file - the way you usually tackle this, is to define the variable globally in the master, and then in the included file(s), use a local variable in each template. Then use the <xsl:with-param /> instruction when calling/applying templates - this way, you've modularized the components and the templates don't depend on any outside stuff. TL;DR:
/Chriztian
is working on a reply...