如何将CDATA插入从Access 2003导出的XML文本标记中? [英] How to insert CDATA into XML text markup exported from Access 2003?
问题描述
我已经从Access 2003中导出了XML,并且尝试使用XSLT在文本字段(拉丁语...)上插入CDATA标记,但是在XSLT中我表现很差...
I've got an XML export from Access 2003 and I tried to insert CDATA tag on text field (latin...) with XSLT but I'm very bad in XSLT...
此处是XML源:
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MESSAGES%20old.xsd" generated="2012-07-31T13:25:46">
<export_x005F_xml_message>
<libelle>h euismod tincidu </libelle>
<price>300</price>
<libelle2>h euirci tation ullamc</libelle2>
</export_x005F_xml_message>
<export_x005F_xml_message>
<libelle>h euismod tincidunt ut lao</libelle>
<price>200</price>
<libelle2>h euirci tation ullamcorper</libelle2>
</export_x005F_xml_message>
</dataroot>
这是我的XSLT的开始...:
Here my XSLT's beginning... :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match='*[name() = "MESSAGES"]'>
<xsl:text disable-output-escaping="yes">
<![CDATA[
</xsl:text>
<xsl:copy-of select="./node()"/>
<xsl:text disable-output-escaping="yes">
]]>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
我想得到类似的东西:
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MESSAGES%20old.xsd" generated="2012-07-31T13:25:46">
<export_x005F_xml_message>
<libelle><![CDATA[h euismod tincidu ]]></libelle>
<price>300</price>
<libelle2><![CDATA[h euirci tation ullamc ]]></libelle>
</export_x005F_xml_message>
<export_x005F_xml_message>
<libelle><![CDATA[h euismod tincidunt ut lao ]]></libelle2>
<price>200</price>
<libelle2><![CDATA[h euirci tation ullamcorper ]]></libelle2>
</export_x005F_xml_message>
</dataroot>
您能帮助我创建正确的XSLT吗? 该XML来自Access 2003,它没有为文本字段提供CDATA选项...我确定通用模型可以帮助像我这样的其他开发人员:-)
Can you help me to create the right XSLT ? This XML is coming from Access 2003 which doesn't provide the CDATA option for text field... I'm sure a generic model could help other developer like me :-)
推荐答案
此处已回答:使用XSLT转换XML并保留CDATA(在Ruby中) ),更好的答案是使用xsl:output.例如...
As already answered here: Transform XML with XSLT and preserve CDATA (in Ruby), a better answer is to use xsl:output. For example ...
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" cdata-section-elements="libelle libelle2" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这篇关于如何将CDATA插入从Access 2003导出的XML文本标记中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!