How to access a variable in CDATA from XSLT?

I am using XSLT Transformation and you need to put some data in the CDATA section and that vale is present in the variable.

Query: how to access a variable in CDATA? Example below:

<xsl:attribute name ="attributeName">
<![CDATA[ 
  I need to access some variable here like
   *<xsl:value-of select ="$AnyVarible"/>* 
 ]]>
</xsl:attribute>

How to use varibale in CDATA? Note: I can not use → &lt;![CDATA[<xsl:value-of select ="$AnyVarible"/>]]&gt; Thanks in advance.

+3
source share
3 answers

I have a solution for this ... FYI for everyone ...

<xsl:text
disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:value-of select ="$AnyVarible"/>
<xsl:text
disable-output-escaping="yes">]]&gt;</xsl:text>
+6
source

If you want to include CDATA sections in your output, you must use the cdata-section attributes of the xsl: output attribute. This is a list of element names. Any such elements will have their own text content wrapped in CDATA.

<xsl:output cdata-section-elements ="foo" />

<foo>
    <xsl:value-of select="$bar' />
</foo>
+3
source

CDATA - , ...

But using an element xsl:output, you must specify which elements should be written as CDATA with an attribute cdata-section-elements.

EDIT:

Now that there is a valid pattern, I assume that you mean this:

<xsl:attribute name ="attributeName">
<![CDATA[ 
   I need to access some variable here like
   *]]><xsl:value-of select ="$AnyVarible"/><![CDATA[* 
]]>
</xsl:attribute>
+2
source

Source: https://habr.com/ru/post/1732834/


All Articles