insert <?xml-stylesheet tag with xsl

2019-03-24 20:01发布

How can I add stylesheet reference with XSLT?

I'm trying to strip down some large input XML with the first transform, and need the second transform to be applied on the client. Thus the first transform has to output the correct reference, e.g.:

<?xml-stylesheet type="text/xsl" href="client.xsl"?>

To recap it's XML->transform1(server)->XML->transform2(client)->HTML

The only way I can make it to work so far is by using xsl:text disable-output-escaping and CDATA:

<xsl:text disable-output-escaping="yes"><![CDATA[<?xml-stylesheet type="text/xsl" href="/efo/efo_class.xsl"?>]]>

Surely there must be a better method.

标签: xml xslt
1条回答
甜甜的少女心
2楼-- · 2019-03-24 20:18

Based on the XSLT spec, Creating Processing Instructions:

<xsl:processing-instruction name="xml-stylesheet">
  <xsl:text>type="text/xsl" href="client.xsl"</xsl:text>
</xsl:processing-instruction>

would create the processing instruction:

<?xml-stylesheet type="text/xsl" href="client.xsl"?>
查看更多
登录 后发表回答