Xsl tries to print '<' as opposed to '& lt;'

Update:

The problem still persists, although it is not quite the same as before. Below is an example of what is being entered, what is being displayed and what I want to get

Input Example:

 &amp;lt;p&amp;gt;&amp;lt;span style=&amp;quot;font-size: medium&amp;quot;&amp;gt;Product description text&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; 

Current output:

 &lt;p&gt;&lt;span style="font-size: medium"&gt;Product description text&lt;/span&gt;&lt;/p&gt; 

Estimated Conclusion:

 <p><span style="font-size: medium">Product description text</span></p> 

.

Using CDATA helped because it allows me to enter '<' but, as you can see in the above output, even when using the disable-output-escaping function, it changed in the output

.

.

The original question:

The error I get is "'<', the hex value 0x3C, is an invalid attribute character

What I'm trying to do is replace all occurrences & lt; and? with <and> respectively.

To make it as simple as possible, here is the code for just lt ;:

 <xsl:variable name="lt"> <xsl:text><</xsl:text> </xsl:variable> <xsl:variable name="lthex">&amp;lt;</xsl:variable> <xsl:copy-of select="ew:replacestring(products_description/node(),$lthex,$lt)"/> 

I tried different things instead of text, for example. value etc.

I know that there is nothing wrong with the code and in the vb code associated with it, because I use it several times to replace and output elsewhere

The problem with this is that I want <and> in the literal sense of the word, not the code that is then viewed by the browser and modified

.

If you need more information, just ask (I'm trying my best to explain this)

Any help would be appreciated

+6
source share
3 answers
 <xsl:text disable-output-escaping="yes"><![CDATA[<]]></xsl:text> 

This is because < is illegal (and therefore your application complains). For > you can use:

 <xsl:text disable-output-escaping="yes">></xsl:text> 
+9
source

Initial task

Input Example:

 &amp;lt;p&amp;gt;&amp;lt;span style=&amp;quot;font-size: medium&amp;quot;&amp;gt;Product description text&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; 

Estimated Conclusion:

 <p><span style="font-size: medium">Product description text</span></p> 

What you really have is a double escape input, so instead of just displaying the text with disable-output-escaping="yes" you need several ways to do the string replacement. Obviously, you are replacing the extension function with ew:replacestring() . The problem is that even if you manage to replace &amp;lt; to < , the result will remain only a string, and the < character will be escaped at the output.

The source code of the replacement was not correctly formed, because < as such is considered markup. Using

 <xsl:variable name="lt"> <xsl:text><![CDATA[<]]></xsl:text> </xsl:variable> 

or

 <xsl:variable name="lt"> <xsl:text>&lt;</xsl:text> </xsl:variable> 

equivalent and fix this problem. However, this does not help in the problem that the replacement character is still displayed as an entity reference. Using disable-output-escaping="yes" here in the variable definition also does not affect this problem.

 <xsl:variable name="lt"> <xsl:text disable-output-escaping="yes">&lt;</xsl:text> </xsl:variable> <xsl:variable name="lt"> <xsl:value-of select="&lt;" disable-output-escaping="yes"> </xsl:variable> 

These code samples do not work because disable-output-escaping="yes" only works when the value is serialized, and not when a variable is assigned.

Possible fix

What you could try to do is save the result of replacing the text in a variable

 <xsl:variable name="replaced-text"> <xsl:copy-of select="ew:replacestring(products_description/node(),$lthex,$lt)"/> </xsl:variable> 

and then output the value of this variable with disable-output-escaping="yes"

 <xsl:value-of select="$replaced-text" disable-output-escaping="yes"/> 

Another solution without extension features

I managed to convert your input

 &amp;lt;p&amp;gt;&amp;lt;span style=&amp;quot;font-size: medium&amp;quot;&amp;gt;Product description text&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt; 

to this exit

 <p><span style="font-size: medium">Product description text</span></p> 

with a slightly modified version of the Jeni Tennison abbreviation replacement template . In your case, a document containing abbreviation headers will look like this:

 <acronyms> <acronym acronym="&amp;lt;">&lt;</acronym> <acronym acronym="&amp;gt;">></acronym> <acronym acronym="&amp;amp;">&amp;</acronym> <acronym acronym="&amp;apos;">'</acronym> <acronym acronym="&amp;quot;">"</acronym> </acronyms> 

The necessary modification should be to modify this part of the sample code.

 <acronym title="{$acronyms[1]}"> <xsl:value-of select="$acronym" /> </acronym> 

to look like this

 <xsl:value-of select="$acronyms[1]" disable-output-escaping="yes"/> 

This template should work in every environment because it is XSLT 1.0 and it does not require any extension functions.

+4
source

Edit: It looks like you're trying to serialize XML or HTML serialization as input instead of XML or HTML serialization and expect it to output XML or HTML serialization?

The right thing is to fix your broken input, but see How to unescape XML characters using XSLT?


You have some kind of misunderstanding here. XSL accepts XML as input and outputs HTML or XML. < represented as &lt; in serialized HTML and XML.

An HTML or XML file containing < that does not run the tag is incorrect serialization (unformed).

&lt; - The correct representation < in the HTML or XML file.

An HTML or XML file is just a serialization of the data that it represents. That is, it is one level below the data that it represents. You should think of the HTML or XML content as what the data represents ( < ), rather than serializing the data ( &lt; ).

Instead, try to explain why you think the problem is with &lt; is a problem, why can we correct a misunderstanding?

0
source

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


All Articles