Ironman
Ironman

Reputation: 556

Can we store SQL query in XSL variable

Can we store a SQL query in a xsl variable?

<xsl:variable name="Query" select="'SELECT X FROM ABC WHERE ID>=2'"/>

If I write like that I am getting error for illegal '>' found,and I have tried another way like this

 <xsl:variable name="Query" select="'SELECT X FROM ABC WHERE ID gt;=2'"/>

Then I am getting illegal '>' element error...

Please help me how to store a query in a variable.

I am using a big query which involves joins and all SQL stuff..I facing the same issue please help me out..

Upvotes: 1

Views: 1959

Answers (2)

Sean B. Durkin
Sean B. Durkin

Reputation: 12729

You just forgot the ampersand character. Use this...

<xsl:variable name="Query" select="'SELECT X FROM ABC WHERE ID &gt;=2'"/>

(& inserted just before gt;)


Please be aware that there is a subtle difference in outcome between

(a)  <xsl:variable name="var-a" select="'some text'"/>

and...

(b)  <xsl:variable name="var-b">some text</xsl:variable>

Option (a) results in $var-a being a node-set (XSLT 1.0) or sequence (XSLT 2.0) containing one node - that node being a text node.

Option (b) results in $var-b being a node-set/sequence containing one node - that node being a result-tree-fragment (XSLT 1.0) or a document node (XSLT 2.0), which in turn contains the text node.

Upvotes: 1

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56182

Use:

<xsl:variable name="Query">SELECT X FROM ABC WHERE ID >= 2</xsl:variable>

or probably more safe and flexible way using <![CDATA[]]>:

<xsl:variable name="Query"><![CDATA[SELECT X FROM ABC WHERE ID >= 2]]></xsl:variable>

Upvotes: 1

Related Questions