我试图将我获得的迭代值放入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>
所以基本上我希望timestamp字段值在CDATA字段中,以便它最终基本上看起来像这样:
<created><![CDATA[2015-04-24 15:07:40]]></created>
感谢您的帮助!
答案 0 :(得分:1)
使用<xsl:output cdata-section-elements="created"/>
。