Reputation: 1752
I am developing an application using symfony2 and twig for templates. The problem comes when trying to use Twig in a XSL file. This is the XSL code with Twig:
<?xml version='1.0' encoding='ISO-8859-1'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
{# src/Anotatzailea/AnotatzaileaBundle/Resources/views/Page/testuaanotatu.html.twig #}
{% extends 'AnotatzaileaAnotatzaileaBundle::layout.html.twig' %}
{% block title %}Testua anotatu{% endblock%}
{% block body %}
<div class="box600_lower">
<xsl:template match="word">
<label>
<xsl:attribute name="class">
<xsl:text>annotation_checkbox</xsl:text>
</xsl:attribute>
<xsl:attribute name="id">
<xsl:text>Ascripta</xsl:text>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:text>Bscripta</xsl:text>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:text>Cscripta</xsl:text>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:text>checkbox</xsl:text>
</xsl:attribute>
</label>
<label>
<xsl:attribute name="class">
<xsl:text>altcheckboxoff</xsl:text>
</xsl:attribute>
<xsl:attribute name="for">
<xsl:text>Ascripta</xsl:text>
</xsl:attribute>
<xsl:attribute name="id">
<xsl:text>Bscripta</xsl:text>
</xsl:attribute>
<xsl:value-of select="text()"/>
<xsl:text> </xsl:text>
</label>
</xsl:template>
</div>
{% endblock %}
</xsl:stylesheet>
The code fails and shows the next message:
Warning: XSLTProcessor::importStylesheet(): compilation error: file /var/www/Symfony/web/MyXSLFile.xsl line 12 element template
Upvotes: 1
Views: 2001
Reputation: 243479
The reason for the compilation error is obvious: An <xsl:stylesheet>
element cannot have any (non-whitespace only) text node children and in the above code you have:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
{# src/Anotatzailea/AnotatzaileaBundle/Resources/views/Page/testuaanotatu.html.twig #}
{% extends 'AnotatzaileaAnotatzaileaBundle::layout.html.twig' %}
{% block title %}Testua anotatu{% endblock%}
{% block body %}
Either this text must be removed by some preprocessor, or they need to be wrapped either in a special element, or in a comment.
Upvotes: 1