Output once if both xml tags occur at the same tim

2019-09-14 16:27发布

问题:

If both xml tags exist I only want the output of the transform to occur once. Is that possible?

xsl

<xsl:template match="latitude | longitude">
   <generate_once>for both tags below</generate_once>
</xsl:template>

xml

<doc>
<latitude /><longitude />
</doc>

回答1:

Will this template do the trick...?

<xsl:template match="latitude | longitude[not(../latitude)]">
   <generate_once>for both tags below</generate_once>
</xsl:template>

This works by matching latitude if it exists (regardless of whether there is a longitude or not). It will only match longitude if there is no latitude though. So, in the case of both being present, only the latitude is matched.



标签: xslt xslt-1.0