简体   繁体   English

XSLT 1.0 - 之后的冗余节点 <xsl :if test ..> 条件

[英]XSLT 1.0 - Redundant Node After <xsl :if test ..> condition

I have an xslt file like below ; 我有一个像下面的xslt文件;

<xsl:if test="/ItemList/Item/cx">
            <kml:Circle>

           </kml:Circle>

</xsl:if>
<xsl:if test="/ItemList/Item/Lon">
            <kml:Point>

          </kml:Point>

</xsl:if>

After executing this xslt on a xml file like the following , it generates redundant tags like <kml:Point/> and <kml:Circle/> . 在如下所示的xml文件上执行此xslt后,它会生成冗余标记,如<kml:Point/><kml:Circle/> But I do not want this tag. 但我不想要这个标签。

Sample XML File 示例XML文件

<ItemList>
  <Item>
    <Name>1</Name>
    <Lon>66.406180329538</Lon>
    <Lat>35.7185924672465</Lat>

  </Item>
  <Item>
    <Name>2</Name>
    <cx>1</cx>
    <cy>2</cy>
    <rx>3</rx>
    <ry>4</ry>
  </Item>
</ItemList> 

After executing xslt on this file sample output is like following ; 在此文件上执行xslt后,示例输出如下所示;

<kml:Placemark>
<kml:Circle cx="1" cy="2" r="3"/>
<kml:Point/>
</kml:Placemark>

<kml:Placemark>
<kml:Circle/>
<kml:Point>
<kml:coordinates>68.406180329538,35.7185924672465</kml:coordinates>
</kml:Point>
</kml:Placemark>

My question is , why there are nodes like <kml:Point/> and <kml:Circle/> after executing this xslt. 我的问题是,为什么在执行这个xslt之后会有像<kml:Point/><kml:Circle/>这样的节点。 I do not want this redundant nodes. 我不想要这个冗余节点。

Thanks for your help 谢谢你的帮助

This XPath expression /ItemList/Item/cx is an absolute location path and it doesn't depend on the context node that had matched the rule on your transformation. 此XPath表达式/ItemList/Item/cx绝对位置路径 ,它不依赖于与转换规则匹配的上下文节点。 In short, it will always select the same nodes, thus it will always have the same boolean value. 简而言之,它将始终选择相同的节点,因此它将始终具有相同的布尔值。

Because your input document has both a cx and a Lon element (in different branch, but they both exist) your xsl:if instructions content will be processed. 因为您的输入文档同时具有cxLon元素(在不同的分支中,但它们都存在),您的xsl:if将处理指令内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM