Subject: Re: [xsl] text extraction From: "James A. Robinson" <jim.robinson@xxxxxxxxxxxx> Date: Thu, 12 Oct 2006 06:50:07 -0700 |
> <E1> text1 <E2> text2 </E2> text3 </E1> > I want to have something like: > text1 text2 text3 Folks have indicated that you can take advantage of the natural processing/handling that XSLT defines, so that something like this would, for your example XML, emit what you wanted: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="text"/> </xsl:stylesheet> But if your markup was more complicated, so it had embedded elements within E1 that you wanted to ignore, you could walk through each node in the document, and on text nodes with the proper parent, emit the normalized string: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="text"/> <xsl:template match="node()"> <xsl:apply-templates select="node()"/> </xsl:template> <xsl:template match="text()[parent::*[self::E1|self::E2]]"> <xsl:sequence select="normalize-space(.)"/> </xsl:template> </xsl:stylesheet> That would let you handle, for example, something like <V><E1>text<E2>text2<baz>smorth</baz></E2>text3<flober>chum</flober></E1></V> Jim - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - James A. Robinson jim.robinson@xxxxxxxxxxxx Stanford University HighWire Press http://highwire.stanford.edu/ +1 650 7237294 (Work) +1 650 7259335 (Fax)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] text extraction, Florent Georges | Thread | [xsl] text() vs xs:string serializa, James A. Robinson |
Re: [xsl] text extraction, Florent Georges | Date | [xsl] text() vs xs:string serializa, James A. Robinson |
Month |