I am using XSLT Transformation and need to put some data in CDATA
section and that value is present in a variable.
Query: How to access variable in CDATA
?
Sample Given Below:
<xsl:attribute name ="attributeName">
<![CDATA[
I need to access some variable here like
*<xsl:value-of select ="$AnyVarible"/>*
]]>
</xsl:attribute>
How can I use varibale in CDATA
?
Note: I can not use --> <![CDATA[<xsl:value-of select ="$AnyVarible"/>]]>
Thanks in advance.
XSLT <xsl:variable> Tip: You can add a value to a variable by the content of the <xsl:variable> element OR by the select attribute!
The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages SGML and XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure.
You cannot - 'variables' in XSLT are actually more like constants in other languages, they cannot change value. Save this answer.
I got the solution for this...FYI for everyone...
<xsl:text
disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:value-of select ="$AnyVarible"/>
<xsl:text
disable-output-escaping="yes">]]></xsl:text>
CDATA is just text like any other element contents...
But using the xsl:output
element you should be able to specify which elements are to be written as CDATA with the cdata-section-elements
attribute.
EDIT:
Now that there is a valid sample, I guess you mean this:
<xsl:attribute name ="attributeName">
<![CDATA[
I need to access some variable here like
*]]><xsl:value-of select ="$AnyVarible"/><![CDATA[*
]]>
</xsl:attribute>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With