关于XML的最好的事情之一就是它只是文本,您可以使用许多通用的文本处理工具来处理它。 但是,有时由于标签妨碍了这种情况,因此效果不佳。 作为developerWorks的作者,我必须以XML模板提交工作,而我通常希望获得一份字数以供我参考。 XML格式的标记和其他标记不计算在内,因此我需要弄清楚如何仅从内容中处理这些信息。 在本技巧中,我将向您展示如何与其他工具结合使用XSLT,甚至单独使用XSLT来解决此问题。
夫人,只是文字
清单1是基于本文草案的格式良好的XML文档的示例。
清单1.示例XML文档
<dw-document xmlns:dw="http://www.ibm.com/developerWorks/">
<!-- ARTICLE TITLE -->
<title>Computing word count in XML documents</title>
<docbody>
<p>One of the best things about XML is that it's just text, and
you can use many general-purpose text processing tools to work with
it. Occasionally, however, this doesn't work so w