开发者

Embedding static CDATA with its tag in XSLT

I need to output from the XSL a sta开发者_如何学Pythontic CDATA construct embedded in the XSL, not from the XML that I am transforming. For example...

<?xml version="1.0"?> 
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">
  <xsl:output method="xml" indent="yes"/>
<!-- ================================================== -->
  <xsl:template match="/">
    <Document>
      <text><![CDATA[
<b>static</b>
<br/><br/>
text
<br/><br/>
      ]]>
      </text>
      <xsl:apply-templates select="//tag"/>
    </Document>
  </xsl:template>
<!-- ================================================== -->
  <xsl:template match="tag">
    So on and so forth...
  </xsl:template>
<!-- ================================================== -->
</xsl:stylesheet>

I want this to output...

<?xml version="1.0"?> 
<Document>
  <text><![CDATA[
<b>static</b>
<br/><br/>
text
<br/><br/>
  ]]>
  </text>
  So on and so forth...
</Document>

But what I get is...

<?xml version="1.0"?> 
<Document>
  <text>
&lt;b&gt;static&lt;/b&gt;
&lt;br/&gt;&lt;br/&gt;
text
&lt;br/&gt;&lt;br/&gt;
  </text>
  So on and so forth...
</Document>

I've tried several combinations of escaping the text and entities, but none seem to work.


Use

<xsl:output cdata-section-elements="text" />

to enforce CDATA for certain elements (spec).

In any case, what you currently get is equivalent to a CDATA section and it should not bother you. (i.e.: If it's bothering you for optical reasons, then get over it. If it is bothering you for technical reasons, fix them.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜