更改代码以匹配父级
<xsl:key name="FHRSID-key" match="EstablishmentDetail" use="FHRSID"/>
<xsl:variable name="lookup-doc" select="doc('lookup.xml')"/>
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[tag[@k = 'fhrs:id' and key('FHRSID-key', @v, $lookup-doc)]]">
<xsl:copy>
<xsl:apply-templates select="@* , node() except tag[@k = 'addr:postcode']"/>
<tag k="addr:postcode" v="{key('FHRSID-key', tag[@k = 'fhrs:id']/@v, $lookup-doc)/PostCode}"/>
</xsl:copy>
</xsl:template>
给予
<osm>
<count>
<tag k="total" v="1560"/>
</count>
<node>
<tag k="fhrs:id" v="111111"/>
<tag k="addr:postcode" v="BA1 111"/>
</node>
<node>
<tag k="fhrs:id" v="222222"/>
<tag k="addr:postcode" v="XXX XXX"/>
</node>
<node>
<tag k="fhrs:id" v="333333"/>
<tag k="addr:postcode" v="BA2 222"/>
</node>
<way>
<tag k="fhrs:id" v="444444"/>
</way>
<way>
<tag k="fhrs:id" v="555555"/>
<tag v="ZZZ ZZZ"/>
<tag k="addr:postcode" v="BA3 333"/>
</way>
</osm>
唯一的问题似乎是
<tag v="ZZZ ZZZ"/>
要素如果您只想保留现有内容,我不确定复制或不复制现有内容的标准是什么
tag k="fhrs:id"
<xsl:template match="*[tag[@k = 'fhrs:id' and key('FHRSID-key', @v, $lookup-doc)]]">
<xsl:copy>
<xsl:apply-templates select="@* , tag[@k = 'fhrs:id']"/>
<tag k="addr:postcode" v="{key('FHRSID-key', tag[@k = 'fhrs:id']/@v, $lookup-doc)/PostCode}"/>
</xsl:copy>
</xsl:template>