📜 ⬆️ ⬇️

Correct textarea in XSLT with XML output method

Probably, many who are beginning to learn XSLT have encountered a problem - textarea in XML output mode is displayed as a single closed tag:
<textarea name="text" id="text"/>
, and not as a pair of tags with a zero child:
<textarea name="text" id="text"></textarea>

And constantly, when meeting this problem, I tried to find its solution on the network, but I could not find it at all - whether the request was wrong for the search engine, or if nobody wanted to share information. In the end, I decided to find a way myself for the correct, without folding, output of this unfortunate textarea. Of course, you can insert characters into this tag and cut them after transformation with a java script, or save the transformation (if the server does it for us, in my case - php) into a variable and with a string replacement, cut out the excess. But we are not looking for easy ways, are we? :-)
In general, by trial and error, there are two ways to deceive the parser (so that it considers that there are children in the tag, although in fact they are not there).

Method 1 .
<textarea name="text" id="text"><xsl:text><![CDATA[]]></xsl:text></textarea>

We give the parser xsl: text and the empty CDATA enclosed in it, and he happily believes that something is in the textarea.
At the exit we have the correct textarea with empty content.

Method 2
<textarea name="text" id="text"><xsl:text>
</xsl:text></textarea>


Add an xsl: text element, inside which there is a line break on the first line (I apologize to the tautology) and zero number of whitespace characters on the second line before the closing tag.
The result is similar to method 1, but, in my opinion, the source code of the template is not quite beautiful in this case.
')
This information does not pretend to be unique, but is of an auxiliary nature to people like me who have not been able to compile the correct search query.

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


All Articles