Subject: Re: [xsl] Novice Question - matching entire text children From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 21 Dec 2010 12:18:14 -0500 |
As already stated this makes a difference for mixed content. Take this simple XML file as sample:
$ cat mixed.xml <a> 1<b>2</b>3</a> $
While string(/a) returns a string, /a/text() returns a node-set: $ xpath++ "string(/a)" mixed.xml 123 $ xpath++ "/a/text()" mixed.xml
################################################################### 1 ################################################################### 3 $
This makes a big difference if applying the often used normalize-space() function to the result. If you want to get the normalized concatenation of the content ("123"/"13") directly applying normalize-space() does not work (for "13"). The reason is that normalize-space() applied to a node-set will only be applied to the first node of that node-set: $ xpath++ "normalize-space(string(/a))" mixed.xml 123 $ xpath++ "normalize-space(/a/text())" mixed.xml 1 $
What I do for getting "13" from mixed.xml: <xsl:variable name="txt"><xsl:copy-of select="text()"/></xsl:variable> <xsl:value-of select="normalize-space($txt)"/>
Not sure whether this is the best way to do it, but it works.
Is getting the same result possible in XPath (1.0)?
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Novice Question - matchin, Hermann Stamm-Wilbra | Thread | Re: [xsl] Novice Question - matchin, Hermann Stamm-Wilbra |
Re: [xsl] flat xml tree to indent o, Wendell Piez | Date | Re: [xsl] Novice Question - matchin, Hermann Stamm-Wilbra |
Month |