简体   繁体   English

如何选择没有文本子元素的元素

[英]How can I select those element which have no text children

In document below I am trying to get those element have no text child. 在下面的文档中,我试图使那些元素没有文本子级。 but every effort get nothing. 但一切努力都无济于事。

<a>
      <b>
         <c> this is nice place </c>
      </b>

      <d> 
         <e> where this place is </e>
         <f> this place is very close to us</f>
      </d>

      <g> 
        <h/>
      </g>

     <i/>
</a>

How about this: 这个怎么样:

//*[not(node())]

Test query here 在这里测试查询

Stylesheet that copies empty elements (immediate children of a ) and their children, if there's not a single text node: 样式表副本空元素(立即儿童a )和他们的孩子,如果有不是一个单一的文本节点:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:apply-templates select="a"/>
  </xsl:template>

  <xsl:template match="a">
    <empty>
      <xsl:copy-of select="*[not(node()/text())]"/>
    </empty>
  </xsl:template>
</xsl:stylesheet>

Result: 结果:

<?xml version="1.0" encoding="utf-8"?>
<empty>
  <g>
    <h />
  </g>
  <i />
</empty>

所以,如果我理解正确的话,你希望所有的孩子a不具有文本节点?

/a/element()[not(.//text())]

暂无
暂无

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

相关问题 如何指定一个元素以具有一个属性,该属性指出它在XML Schema中包含多少个子元素? - How can I specify an element to have an attribute that states how many children it contains in an XML Schema? 在XML模式中,如何定义可以具有文本节点而不能具有文本节点的元素 - In XML Schema, how to define an element which can have a text node and one which cannot XPATH表达式选择有两个有孩子的父母 - XPATH Expression to Select Parent With Two Children Which Have Children 如何定义XSD元素有多个子元素,所有子元素都很简单,只有属性? - How to define XSD element to have multiple children, all of which are simple and only have attributes? 我有一个 xml 文件,其中包含许多特殊字符,我需要找出这些特殊字符并将它们的不同列表放入文本文件中 - I have a xml file which is having lots of special characters which I need to find out and put the distinct list of those into a text file Minidom:我如何检查我是否有预期的根和孩子? - Minidom: How can I check if I have the expected root and children? 如何查看节点有多少个子节点? - How can I check how many children does a node have? 如何仅排序元素的某些子代? - How can I sort only some children of an element? XSLT 如何只选择带有子元素的元素的值 - XSLT How to select only the value of an element with children 如何选择具有多个子元素的所有元素,这些子元素的属性均不等于特定值 - How can I select an element with multiple child elements all of which having attributes not equal to a specific value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM