私の質問は、XSLTを使用して、次の変換をどのように実行できるかということです。
ウェイ要素によって参照されていないすべてのノード要素をフィルタリングします。
ソースxmlドキュメントに含まれていないノード要素を参照するway要素をフィルタリングします。
属性「visible」を「false」に変更し、「tag」の子要素を持たない「node」要素に変更します。
この変換は、次の3つの要件すべてを満たします。
<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:key name="kND-By-Ref" match="way/nd" use="@ref"/>
<xsl:key name="kNodeById" match="node" use="@id"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node[not(key('kND-By-Ref', @id))]"/>
<xsl:template match="way[nd[not(key('kNodeById', @ref))]]"/>
<xsl:template match="node[not(tag)]/@visible">
<xsl:attribute name="visible">false</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
このXMLドキュメントに適用した場合(各要件のケースを含めるために適切に作成されます):
<osm version="0.6" generator="CGImap 0.0.2">
<node id="1726631203" lat="50.8500083" lon="4.3553223" visible="true"
version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z">
<tag/>
</node>
<node id="1726631223" lat="50.8500083" lon="4.3553223" visible="true"
version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
<node id="ZZZZZZZ" lat="50.8500083" lon="4.3553223" visible="true"
version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
<way id="160611697" user="toSc" uid="246723" visible="true"
version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
<nd ref="1726631203"/>
<nd ref="1726631223"/>
</way>
<way id="160611698" user="toSc" uid="246723" visible="true"
version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
<nd ref="1726631203"/>
<nd ref="1726631223"/>
<nd ref="1726631213"/>
<nd ref="1726631205"/>
<nd ref="1726631185"/>
<nd ref="1726631203"/>
</way>
</osm>
必要な正しい結果(すべてのフィルタリングが実行され、要素visible
の1つの属性がに向けられます)が生成されます:node
false
<osm version="0.6" generator="CGImap 0.0.2">
<node id="1726631203" lat="50.8500083" lon="4.3553223"
visible="true" version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z">
<tag/>
</node>
<node id="1726631223" lat="50.8500083" lon="4.3553223"
visible="false" version="6" changeset="9938190" timestamp="2011-11-24T22:05:32Z"/>
<way id="160611697" user="toSc" uid="246723" visible="true"
version="1" changeset="11385198" timestamp="2012-04-22T14:57:19Z">
<nd ref="1726631203"/>
<nd ref="1726631223"/>
</way>
</osm>
説明:
IDルールは3つのテンプレートによってオーバーライドされ、それぞれが3つの要件のいずれかを実装します。
空のボディを持つ2つのオーバーライドテンプレートは、2つのフィルタリング要件を実装します。
node
キーを使用して、id
属性でnd
sを、属性でsを便利かつ効率的に検索していref
ます。
属性値の置換要件は、3番目のオーバーライドテンプレートに実装されています。