如何通过XSLT

时间:2018-04-19 10:32:22

标签: java xml xslt cdata xml-formatting

我想在我的xml数据中添加节点并保持CDATA格式不变,我有xml文件,其中我写了xml内容,应该在我的shablon xml中复制 这里是xml contetn,应该添加到shablon.xml

<?xml version="1.0" encoding="UTF-8"?><Data>
<RawData Format="Text">
<organizationNameEng>fgfgfg</organizationNameEng>
<organizationNameGeo>dfdfdf</organizationNameGeo>
<organizationIdentifier>123456789</organizationIdentifier>
<cardNumber>dfdfdf</cardNumber></RawData>
<response>
<id>0123</id>
<content>her  is  content</content>
</response>
</Data>

here  is  my  shablon xml 
<?xml version="1.0" encoding="UTF-8"?><DataPrep xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Lcid="String">
<Job Name="CompleteJob" Type="Normal" Priority="1">
<JobDetails>![CDATA[ here is  job  details ]]</JobDetails>
<DetailData>
<Information>
<RawData Format="Text"><</RawData>
</Data>
<response>
...
</response>
</Information>
</DetailData>
</Job>

这是我的xlst

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes" cdata-section-elements="RawData"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Detaildata/information">
        <xsl:copy>
            <xsl:copy-of select="document('content.xml')"/>
    </xsl:template>
        </xsl:copy>

</xsl:stylesheet>

这将给我这样的回应:

<?xml version="1.0" encoding="UTF-8"?><DataPrep xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Lcid="String">
<Job Name="CompleteJob" Type="Normal" Priority="1">
<JobDetails>&lt here is  job  details &gt</JobDetails>
<DetailData>
<Information>
<RawData Format="Text"><![CDATA[
<organizationName>fgfgfg</organizationNameEn>
<organizationIdentifier>123456789</organizationIdentifier>
<cardNumber>dfdfdf</cardNumber>
]]></RawData>
</Data>
</Information>
</DetailData>
</Job>
</DataPrep>

我应该如何更改我的xslt文件,我可以在其中粘贴标签..]]以及我应该如何避免xslt中的响应标记并且不会使用{{1}更改<CDATA>格式的情况这里

&gt  &lt

0 个答案:

没有答案