How to create PHP / JSP / ERB tags using XSLT?

I have a bunch of XML files that I use to create HTML pages. These pages eventually become visible (manually) with some <%= %> tags and are made in Ruby.erb templates.

Is there a way to generate special tags <?php ?> Or <%= %> directly during the XSL conversion?

I tried using the <![CDATA[ ... ]]> block, but then the output is generated with &lt; and &gt; instead of < and > .

+4
source share
1 answer
 Is there a way to generate the special tags <?php ?> or <%= %> directly during the XSL transform? 

<?php ?> not a "special tag" - it is a standard node type in the XPath data model - processing instructions .

There is also an XSLT instruction for creating PI:

<xsl:processing-instruction>

Finally, you can create text like "<% =%>" if you use the text output method:

 <xsl:output method="text"/> 

but in the text output method, you lose the node - you must enter each output character as text.

So, it’s a little more convenient to use the default xml output method and the attribute (optional!) disable-output-escaping="yes" if supported by your XSLT processor.

Here is an example :

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/"> <xsl:processing-instruction name="php"/> <xsl:text disable-output-escaping="yes"> &lt;% Hello World! %> </xsl:text> </xsl:template> </xsl:stylesheet> 

Applying this transformation to any XML document (not used) creates :

 <?php?> <% Hello World! %> 
+4
source

All Articles