The right pattern or test is processing-instruction('lastUpdatedOn')
. I would stuff it into the match of the p
e.g.
<xsl:template match="p[processing-instruction('lastUpdatedOn')]">
<xsl:copy>
<xsl:apply-templates select="@*, processing-instruction('lastUpdatedOn'), node() except processing-instruction('lastUpdatedOn')"/>
</xsl:copy>
</xsl:template>
<xsl:template match="processing-instruction('lastUpdatedOn')">
<xsl:attribute select="{name()}" select="."/>
</xsl:template>
the rest can be handled by the identity transformation with e.g. <xsl:mode on-no-match="shallow-copy"/>
.
As you seem to have multiple processing instruction sorting them with
<xsl:template match="p[processing-instruction('lastUpdatedOn')]">
<xsl:copy>
<xsl:apply-templates select="@*, sort(processing-instruction('lastUpdatedOn'), (), function($p) { xs:date(replace($p, '([0-9]{2})/([0-9]{2})/([0-9]{4})', '$3-$2-$1')) })[last()], node() except processing-instruction('lastUpdatedOn')"/>
</xsl:copy>
</xsl:template>
<xsl:template match="processing-instruction('lastUpdatedOn')">
<xsl:attribute name="lastupdatedon" select="."/>
</xsl:template>
can help to just display the last date. Higher-order fn:sort
is available in Saxon PE and EE since 9.8 at least and in Saxon HE for 10 and later.
The above would move the date to the attribute but delete the processing instructions from the p
, if you need to retain them perhaps
<xsl:template match="p[processing-instruction('lastUpdatedOn')]">
<xsl:copy>
<xsl:apply-templates select="@*, sort(processing-instruction('lastUpdatedOn')!xs:date(replace(., '([0-9]{2})/([0-9]{2})/([0-9]{4})', '$3-$2-$1')))[last()], node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match=".[. instance of xs:date]">
<xsl:attribute name="lastupdatedon" select="."/>
</xsl:template>
is a better approach.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…