【发布时间】:2015-12-11 14:15:37
【问题描述】:
在使用以下 XSLT 删除 CDATA 时,某些元素在 CDATA 不存在的地方被删除。
有人可以解释一下代码吗?我在哪里犯错。谢谢。
输入:
<?xml version="1.0" encoding="UTF-8"?>
<response status="200">
<CrsCreateCourseExpResponse>
<pCategoryOut>
<![CDATA[<XX_IL_OLM_CRS_CAT_TAB_OBJ>Y<XX_IL_OLM_CRS_CAT_TAB_OBJ>]]>
</pCategoryOut>
<pLearnerAccessOut>
<![CDATA[<XX_IL_OLM_LRNR_ACC_TAB_OBJ><P_OLM_LRNR_ACC_ERRORS>N</P_OLM_LRNR_ACC_ERRORS></XX_IL_OLM_LRNR_ACC_TAB_OBJ>]]>
</pLearnerAccessOut>
<pActivityVersionId>42002</pActivityVersionId>
<pOvn>1</pOvn>
<pErrorCode>0</pErrorCode>
<pErrorMsg>success</pErrorMsg>
</CrsCreateCourseExpResponse>
</response>
输出:
<?xml version="1.0"?>
<response status="200">
<XX_IL_OLM_CRS_CAT_TAB_OBJ>Y<XX_IL_OLM_CRS_CAT_TAB_OBJ>
<XX_IL_OLM_LRNR_ACC_TAB_OBJ>
<P_OLM_LRNR_ACC_ERRORS>N</P_OLM_LRNR_ACC_ERRORS>
</XX_IL_OLM_LRNR_ACC_TAB_OBJ>
4200210success
</response>
期望的输出:
<?xml version="1.0" encoding="UTF-8"?>
<response status="200">
<CrsCreateCourseExpResponse>
<pCategoryOut>
<XX_IL_OLM_CRS_CAT_TAB_OBJ>Y<XX_IL_OLM_CRS_CAT_TAB_OBJ>
</pCategoryOut>
<pLearnerAccessOut>
<XX_IL_OLM_LRNR_ACC_TAB_OBJ><P_OLM_LRNR_ACC_ERRORS>N</P_OLM_LRNR_ACC_ERRORS></XX_IL_OLM_LRNR_ACC_TAB_OBJ>
</pLearnerAccessOut>
<pActivityVersionId>42002</pActivityVersionId>
<pOvn>1</pOvn>
<pErrorCode>0</pErrorCode>
<pErrorMsg>success</pErrorMsg>
</CrsCreateCourseExpResponse>
</response>
我正在使用的 XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="name/text()">
<xsl:value-of select="." disable-output-escaping="yes" />
<Language>English</Language>
</xsl:template>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
【问题讨论】: