我有一个很大的 XML 文件,我正在尝试编写循环遍历整个节点集(PRESOL、COMBINE 和 FAIROPS)并删除所有名为 DATE 的子节点的 XSLT。然后,我想将父节点的 DATE 重新格式化为 mm/dd/yyyy。这是我的代码,我使用的是 1.0 版:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="DATE">
<xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:value-of select="concat(substring(., 1, 2), '/', substring(., 3, 2), '/', substring(., 5, 4))"/>
<xsl:text disable-output-escaping="yes"></</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="DATE[preceding::DATE]"/>
我很难理解如何遍历整个节点集。我希望不要硬编码父节点名称。目前,我的代码只处理第一个父节点。此外,如果父节点没有子节点,我的代码将删除它的 DATE 节点,我不明白为什么。任何帮助将不胜感激。
我的意见
<NOTICES>
<PRESOL>
<DATE>01242013</DATE>
<AGENCY><![CDATA[Department of the Interior]]></AGENCY>
<OFFICE><![CDATA[Fish and Wildlife Service]]></OFFICE>
<LOCATION><![CDATA[CGS-WO]]></LOCATION>
<ZIP>97232</ZIP>
<CHANGES>
<MOD>
<DATE>01242013</DATE>
<AGENCY><![CDATA[Department of the Interior]]></AGENCY>
<OFFICE><![CDATA[Fish and Wildlife Service]]></OFFICE>
<LOCATION><![CDATA[CGS-WO]]></LOCATION>
<ZIP>97232</ZIP>
</MOD>
</CHANGES>
</PRESOL>
<COMBINE>
<DATE>02102013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Air Force Materiel Command]]></OFFICE>
<LOCATION><![CDATA[Tinker OC-ALC - (Central Contracting)]]></LOCATION>
<ZIP>73145-3015</ZIP>
</COMBINE>
<COMBINE>
<DATE>02092013</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Military Sealift Command]]></OFFICE>
<LOCATION><![CDATA[MSC Norfolk]]></LOCATION>
</COMBINE>
<COMBINE>
<DATE>02092013</DATE>
<AGENCY><![CDATA[Department of Veterans Affairs]]></AGENCY>
<OFFICE><![CDATA[Grand Junction VAMC)]]></OFFICE>
<LOCATION><![CDATA[Veterans Affairs Medical Center]]></LOCATION>
</COMBINE>
<PRESOL>
<DATE>12272012</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
<CHANGES>
<MOD>
<DATE>01112013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
<MOD>
<DATE>01112013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
<MOD>
<DATE>01142013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
<MOD>
<DATE>01142013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
</CHANGES>
</PRESOL>
<FAIROPP>
<DATE>02082013</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Bureau of Medicine and Surgery]]></OFFICE>
<LOCATION><![CDATA[NH Camp Pendleton]]></LOCATION>
<ZIP>92055</ZIP>
<CHANGES>
<MOD>
<DATE>02122011</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
</CHANGES>
</FAIROPP>
</NOTICES>
期望的输出:
<NOTICES>
<PRESOL>
<DATE>01/24/2013</DATE>
<AGENCY><![CDATA[Department of the Interior]]></AGENCY>
<OFFICE><![CDATA[Fish and Wildlife Service]]></OFFICE>
<LOCATION><![CDATA[CGS-WO]]></LOCATION>
<ZIP>97232</ZIP>
<CHANGES>
<MOD>
<AGENCY><![CDATA[Department of the Interior]]></AGENCY>
<OFFICE><![CDATA[Fish and Wildlife Service]]></OFFICE>
<LOCATION><![CDATA[CGS-WO]]></LOCATION>
<ZIP>97232</ZIP>
</MOD>
</CHANGES>
</PRESOL>
<COMBINE>
<DATE>02/10/2013</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Air Force Materiel Command]]></OFFICE>
<LOCATION><![CDATA[Tinker OC-ALC - (Central Contracting)]]></LOCATION>
<ZIP>73145-3015</ZIP>
</COMBINE>
<COMBINE>
<DATE>02/09/2013</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Military Sealift Command]]></OFFICE>
<LOCATION><![CDATA[MSC Norfolk]]></LOCATION>
</COMBINE>
<COMBINE>
<DATE>02/09/2013</DATE>
<AGENCY><![CDATA[Department of Veterans Affairs]]></AGENCY>
<OFFICE><![CDATA[Grand Junction VAMC)]]></OFFICE>
<LOCATION><![CDATA[Veterans Affairs Medical Center]]></LOCATION>
</COMBINE>
<PRESOL>
<DATE>12/27/2012</DATE>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
<CHANGES>
<MOD>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
<MOD>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
<MOD>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
<MOD>
<AGENCY><![CDATA[Department of the Air Force]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
</CHANGES>
</PRESOL>
<FAIROPP>
<DATE>02/08/2013</DATE>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Bureau of Medicine and Surgery]]></OFFICE>
<LOCATION><![CDATA[NH Camp Pendleton]]></LOCATION>
<ZIP>92055</ZIP>
<CHANGES>
<MOD>
<AGENCY><![CDATA[Department of the Navy]]></AGENCY>
<OFFICE><![CDATA[Pacific Air Forces]]></OFFICE>
<LOCATION><![CDATA[354 CONS - Eielson]]></LOCATION>
</MOD>
</CHANGES>
</FAIROPP>
</NOTICES>