My question is how, using XSLT, could I do the following
transformation ?
过滤所有未以任何方式被元素引用的节点元素 。
过滤源 xml 文档中没有包含的引用节点元素元素的方式 。
将属性“ 可见” 改为“ 假”, 改为“ 节点” 元素, 没有“ 标签” 子元素 。
<强 > 此转换完全满足所有三个要求: 强>
<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 文档 strong > (适当创建以包含每项要求的立案) 时 < strong > :
<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>
the wanted, 正确结果 (所有过滤都进行, visible
属性被转换为 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>
<强度 > 排除 强度 > :
身份规则被三个模板取代,每个模板执行三项要求中的一个。
有空机构的两个压倒一切的模板执行两个过滤要求。
我们使用密钥方便而高效地查找 node
s, 其 id
属性和 d
s 属性, 其 ref
属性。
在第三个压倒一切的模板中执行属性值重置要求。