把xsl:value-of..在CDATA内部



我正在尝试将通过迭代获得的值放入 CDATA 字段中。是否有可能在 XSLT 中执行此操作?

我的 XML 文件:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="XSLTest.xsl"?>
<pages>
  <page>
      <title>New Title</title>
      <id>4782</id>
      <timestamp>2012-09-13 13:15:33</timestamp>
      <contributor>
        <username>kf</username>
        <id>2</id>
      </contributor>
      <text xml:space="preserve"> 
      some text
    </text>
 </page>
 </pages>

我的 XSL 文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
    <xsl:for-each select="pages/page">
    <content>
        <id><xsl:value-of select="id"/></id>
        <title><xsl:value-of select="title"/></title>
        <alias><xsl:value-of select="title"/></alias>
        <introtext><xsl:value-of select="text"/></introtext>
        <created><xsl:value-of select="timestamp"/></created> //This value in a CDATA Field
        <created_by><xsl:value-of select="contributor/username"/></created_by>
        <modified_by><xsl:value-of select="contributor/username"/></modified_by>
    </content>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

所以基本上我希望时间戳字段值位于 CDATA 字段中,以便它最终基本上看起来像这样:

<created><![CDATA[2015-04-24 15:07:40]]></created>

感谢您的帮助!

使用 <xsl:output cdata-section-elements="created"/> .

最新更新