[英]Put xsl:value-of… inside 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"/>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.