已知:
将出现日期的属性的
源代码模型
<root>
<parent attr-1="1000" attr-2="abc" DateAttributeParent="10.11.2017">
<child attr-3="whatever" attr-4="whatever2" DateAttributeChild="09.12.2010"> </child>
</parent>
<parent attr-1="2222" attr-2="abc" DateAttributeParent="04.06.2016">
<child attr-3="whatever" attr-4="whatever2" DateAttributeChild="02.06.2009"> </child>
</parent>
</root>期望输出
<root>
<parent attr-1="1000" attr-2="abc" DateAttributeParent="2017.11.10">
<child attr-3="whatever" attr-4="whatever2" DateAttributeChild="2010.12.09"> </child>
</parent>
<parent attr-1="2222" attr-2="abc" DateAttributeParent="2016.06.04">
<child attr-3="whatever" attr-4="whatever2" DateAttributeChild="2009.06.02"> </child>
</parent>
</root>发布于 2019-12-01 00:22:00
这有点乏味,但在其他方面却是微不足道的:
XSLT1.0
<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"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@DateAttributeParent | @DateAttributeChild">
<xsl:attribute name="{name()}">
<xsl:value-of select="substring-after(substring-after(., '.'), '.')"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="substring-before(substring-after(., '.'), '.')"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="substring-before(., '.')"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/59121261
复制相似问题