Subject: Re: [xsl] Convert text nodes to a single string From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 9 Mar 2022 13:34:51 -0000 |
Hey Rick, Perhaps another way to accomplish your goal is simply a test on whether such a text node child exists: exists(child::text()[matches(.,'\S')]) returns true when a child text node has any non-whitespace content. Cheers, Wendell On Wed, Mar 9, 2022 at 8:26 AM rick@xxxxxxxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi All, > > > > I am trying to flatten a messy XHTML file by unwrapping any elements that > donbt have non-whitespace text nodes. I am trying to return a single string > from all of the text nodes in an element and see if its normalized value is > an empty string. Here is my sample input: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <root>This has <b>some </b>text.</root> > > > > Here is my stylesheet: > > > > <?xml version="1.0" encoding="UTF-8"?> > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > xmlns:xs="http://www.w3.org/2001/XMLSchema" > > xmlns:math="http://www.w3.org/2005/xpath-functions/math" > > xmlns:rq="http://www.frameexpert.com/functions" > > exclude-result-prefixes="xs math rq" > > version="3.0" expand-text="yes"> > > > > <xsl:output indent="yes"/> > > > > <xsl:strip-space elements="td"/> > > > > <xsl:template match="/root"> > > <xsl:message>{text()}</xsl:message> > > <xsl:message>{count(text())}</xsl:message> > > <xsl:message>{count(rq:getStringFromText(text()))}</xsl:message> > > <xsl:apply-templates/> > > </xsl:template> > > > > <xsl:function name="rq:getStringFromText" as="xs:string*"> > > <xsl:param name="text-nodes"/> > > <xsl:for-each select="$text-nodes"> > > <xsl:value-of select="normalize-space(.)"/> > > </xsl:for-each> > > </xsl:function> > > > > </xsl:stylesheet> > > > > I expected that this line > > > > <xsl:message>{count(rq:getStringFromText(text()))}</xsl:message> > > > > would return 1, but instead I get 2. Perhaps I need recursion in my > function. Thank you in advance. > > > > Rick > > > XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> > EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by > email <>) > -- ...Wendell Piez... ...wendell -at- nist -dot- gov... ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Convert text nodes to a s, Martin Honnen martin | Thread | Re: [xsl] Convert text nodes to a s, rick@xxxxxxxxxxxxxx |
Re: [xsl] Convert text nodes to a s, Martin Honnen martin | Date | Re: [xsl] Convert text nodes to a s, rick@xxxxxxxxxxxxxx |
Month |