开发者

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

开发者 https://www.devze.com 2023-01-22 08:08 出处:网络
I have a bunch of XML files which I use to generate HTML pages. Those pages ultimately get marked up (by hand) with some <%= %> tags and made into Ruby .erb templates.

I have a bunch of XML files which I use to generate HTML pages. Those pages ultimately get marked up (by hand) with some <%= %> tags and made into Ruby .erb templates.

Is there a w开发者_StackOverflow中文版ay to generate the special tags <?php ?> or <%= %> directly during the XSL transform?

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


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

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

there is also an XSLT instruction to create a 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 loseany node -- you should enter every output character as text.

So, it is a little-bit more convenient to use the default xml output method and the (non-mandatory!) attribute disable-output-escaping="yes" if this is 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) produces:

<?php?>
     <% Hello World! %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号