我必须使用XSLT从一个XML转换为另一个XML。我的源文件中有一些命名空间,并且在所需的文件中,我必须保留所有这些命名空间,除了更改xsi:schemaLocation
的值并在<resource>
节点中添加adlcp:scormtype="sco"
属性。XSLT:更改名称空间的值
我的输入文件:
<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="eXescorm_quiz4823c6301f3d3afc1c1f"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
<resources>
<resource identifier="RES22" type="webcontent" href="index.html">
<file href="index.html"/>
<file href="common.js"/>
</resource>
</resources>
</manifest>
所需的输出:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
identifier="eXeorm_sample4823c6301f29a89a4c1f"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://www.imsproject.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd">
<resources>
<resource identifier="RES22" type="webcontent" href="index.html" adlcp:scormtype="sco">
<file href="index.html"/>
<file href="common.js"/>
</resource>
</resources>
</manifest>
我的XSLT(更新)
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2"
xmlns:xhtml="http://www.imsglobal.org/xsd/imscp_v1p1"
xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"
exclude-result-prefixes="xhtml">
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:resource[@type='webcontent']"
xmlns="http://www.w3.org/1999/xhtml">
<resource adlcp:scormtype="sco">
<xsl:apply-templates select="
(@*[local-name()!='adlcp:scormtype'])
| node()"/>
</resource>
</xsl:template>
请帮我改变命名空间的价值xsi:schemalocation
谢谢!
非常感谢。这是完美的。 :) 结合我的两个解决方案的不同问题后,我有一分钟的问题,我将作为一个新的问题发布。再次感谢你的帮助。 :) – RahulD 2012-08-10 02:58:26
@rahuldwivedi:不客气。 – 2012-08-10 03:27:53