XSL - XSL y Javascript

 
Vista:

XSL y Javascript

Publicado por Ser@fo (1 intervención) el 18/09/2004 03:15:01
Good Afternoon,

I hace this in a XSL file:
<script language="javascript">

<![CDATA[

function fValidateForm(action,target)
{
for(i=0;i<=5;i++)
{
alert(i);
}
}
]]>

</script>


I a working with Netbeans, when the browser loads the page, which generates
HTML, I got a sintax error. When a right clik the page to se the source
code, y Realize that the function change for this:


function fValidateForm(action,target)
{
for(i=0;i<=5;i++)
{
alert(i);
}
}


Wath will be the problem?? Any help?? Thanks a Lot.

Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

JavaScript Syntax Error in XSLT Output

Publicado por Alejandro (227 intervenciones) el 05/07/2023 00:07:15
The issue you're experiencing is likely due to the way XSLT handles the `<script>` element with embedded JavaScript code. XSLT processors may try to parse and modify the content of the `<script>` element during the transformation, which can result in changes or errors in the JavaScript code.

To address this issue, you can try the following solutions:

1. CDATA Section: Wrap your JavaScript code inside a CDATA section to ensure that it is treated as text and not processed by the XSLT processor. Modify your code as follows:

1
2
3
4
5
6
7
8
9
<script language="javascript">
  <![CDATA[
  function fValidateForm(action,target) {
    for(i=0;i<=5;i++) {
      alert(i);
    }
  }
  ]]>
</script>

2. Escape Special Characters: Another approach is to escape special characters in your JavaScript code. Replace certain characters with their corresponding HTML entities to prevent the XSLT processor from interpreting them. For example:

1
2
3
4
5
6
7
<script language="javascript">
function fValidateForm(action,target) {
  for(i=0;i&lt;=5;i++) {
    alert(i);
  }
}
</script>

By escaping the less-than symbol `<` as `&lt;`, you ensure that it is treated as plain text and doesn't interfere with the XSLT transformation.

Try either of these approaches and see if the JavaScript code is preserved correctly in the generated HTML. Remember to test your resulting HTML output to ensure that the JavaScript code functions as expected.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar