我有以下xml:
<?xml version="1.0" encoding="UTF-8"?>
<comments xmlns="http://www.dsttechnologies.com/awd/rest/v1">
<row xmlns="">
<source>SYSTEM</source>
<group>PRTL-TASK</group>
<type>text/plain</type>
<text mimetype="text/plain">Assigned to: DT73606</text>
<date>2015-08-18</date>
<posted>8 days ago</posted>
<time>04:04:58-05:00</time>
<userNameInfo href="awdServer/awd/services/v1/users/DT73606" userId="DT73606" id="1e1fd97d-2d14-4939-a009-5c94fdb7b754">
<lastName xmlns="http://www.dsttechnologies.com/awd/rest/v1">All powerful UserId</lastName>
</userNameInfo>
<instanceId>2015-07-29-04.27.15.461040T01</instanceId>
<link rel="self" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01/history/comments/b5ee129a-0338-41c7-881b-ab8c1727de36" />
<link rel="parent instance" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01" />
</row>
<row xmlns="">
<source>MANUAL</source>
<group>PRTL-TASK</group>
<type>text/plain</type>
<text mimetype="text/plain">hai hello</text>
<date>2015-07-29</date>
<posted>3 weeks ago</posted>
<time>09:04:25-05:00</time>
<userNameInfo href="awdServer/awd/services/v1/users/DT73606" userId="DT73606" id="1e1fd97d-2d14-4939-a009-5c94fdb7b754">
<lastName xmlns="http://www.dsttechnologies.com/awd/rest/v1">All powerful UserId</lastName>
</userNameInfo>
<instanceId>2015-07-29-04.27.15.461040T01</instanceId>
<link rel="self" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01/history/comments/6c09f55e-f06f-4fa1-abe4-4bc4eed14e6d" />
<link rel="parent instance" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01" />
</row>
</comments>
我正在尝试使用XSLT修改上面的xml,输出如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<History>
<comments>
<row>
<source>SYSTEM</source>
<group>PRTL-TASK</group>
<type>text/plain</type>
<text mimetype="text/plain">Assigned to: DT73606</text>
<date>2015-08-18</date>
<posted>8 days ago</posted>
<time>04:04:58-05:00</time>
<userNameInfo href="awdServer/awd/services/v1/users/DT73606" userId="DT73606" id="1e1fd97d-2d14-4939-a009-5c94fdb7b754">
<lastName>All powerful UserId</lastName>
</userNameInfo>
<instanceId>2015-07-29-04.27.15.461040T01</instanceId>
<link rel="self" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01/history/comments/b5ee129a-0338-41c7-881b-ab8c1727de36" />
<link rel="parent instance" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01" />
</row>
<row>
<source>MANUAL</source>
<group>PRTL-TASK</group>
<type>text/plain</type>
<text mimetype="text/plain">hai hello</text>
<date>2015-07-29</date>
<posted>3 weeks ago</posted>
<time>09:04:25-05:00</time>
<userNameInfo href="awdServer/awd/services/v1/users/DT73606" userId="DT73606" id="1e1fd97d-2d14-4939-a009-5c94fdb7b754">
<lastName>All powerful UserId</lastName>
</userNameInfo>
<instanceId>2015-07-29-04.27.15.461040T01</instanceId>
<link rel="self" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01/history/comments/6c09f55e-f06f-4fa1-abe4-4bc4eed14e6d" />
<link rel="parent instance" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2015-07-29-04.27.15.461040T01" />
</row>
</comments>
</History>
最终目标是消除命名空间。我正在尝试使用以下XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="http://www.dsttechnologies.com/awd/rest/v1" version="2.0" exclude-result-prefixes="v">
<xsl:strip-space elements="*" />
<xsl:output indent="yes" omit-xml-declaration="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="v:comments">
<History>
<xsl:copy>
<xsl:apply-templates select="v:comment" />
</xsl:copy>
</History>
</xsl:template>
<xsl:template match="v:comment">
<row>
<xsl:apply-templates mode="sans-namespace" />
</row>
</xsl:template>
<xsl:template match="*" mode="sans-namespace">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
尽管使用了exclude-result-prefixes="v"
,但我没有获得所需的输出。有人可以指出这里有什么问题吗?