使用这个单一的 XPath 表达式:
/*/*[not(string-length(preceding-sibling::*|following-sibling::*)
>
string-length()
)
]
基于 XSLT 的验证:
<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:template match="/">
<xsl:copy-of select=
"/*/*[not(string-length(preceding-sibling::*|following-sibling::*)
>
string-length()
)
]"/>
</xsl:template>
</xsl:stylesheet>
当此转换应用于提供的 XML 文档时:
<record>
<url1>http://www.google.com</url1>
<url2>http://www.bing.com</url2>
</record>
对 Xpath 表达式求值,并将该求值的结果(选定元素)复制到输出:
<url1>http://www.google.com</url1>