[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Testing if first child is text or an element?
I pulled it out as a named template because I needed to test the general conditions in many places. Performance currently isn't an issue. After this conversion effort this code will not have a use.I may have more of these mixed content situations to handle and will keep this in mind for a possible restructure.B Sent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: "Piez, Wendell A. (Fed) wendell.piez@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: 4/15/24 5:22 PM (GMT-08:00) To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Testing if first child is text or an element? Hi, B Instead of a conditional on the container, how about handling only the node we want to amend? B <xsl:template match=binfo/child::text()[1][matches(.,b\Sb)]b> B B <xsl:text>+</xsl:text> B B <xsl:next-match/> </xsl:template> B Much simpler, I think, probably also performs better. B Apologies if I misconstrue the question! B Cheers, Wendell B From: dvint dvint@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Monday, April 15, 2024 6:08 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Testing if first child is text or an element? B That did the trick. Figured I needed a normalize-space in there somewhere, just not sure how to add it. B B B Sent from my Verizon, Samsung Galaxy smartphone B B -------- Original message -------- From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: 4/15/24 12:35 PM (GMT-08:00) To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Testing if first child is text or an element? B On 15/04/2024 21:29, dvint@xxxxxxxxx wrote: > I've got some markup that allows mixed content in an element. When I > process this content I need to do something different if the element > starts with text vs an element. My content can be like this: > > <?xml version="1.0" encoding="UTF-8"?> > <doc> > B <step > > B B B <info> > B B B B B 1 The following collection shows examples of non-checklist > B B B B B lists with nested checklists. > B B B B B <ul> > B B B B B B B B <li>This is an unordered list item with a child > B B B B B B B B B B B checklist. > B B B B B B B B </li> > B B B B B </ul> > B B B </info> > B </step> > B <step > > B B B <info> > B B B B B B <p>2 The following collection shows examples of non-checklist > B B B B B B B lists with nested checklists.</p> > B B B B B B <ul> > B B B B B B B B B <li>This is an unordered list item with a child > B B B B B B B B B B checklist. > B B B B B B B B B </li> > B B B B B B </ul> > B B </info> > B </step> > </doc> > > I want it to produce: > > + > 1 The following collection shows examples of non-checklist > lists with nested checklists. > * This is an unordered list item with a child > checklist. > > 2 The following collection shows examples of non-checklist > lists with nested checklists.</p> > * This is an unordered list item with a child > > So if the <info> starts with text it should add the '+' and if it > starets with an element, add nothing. > > > > B B B B <xsl:template name="list-block-start"> > > B B B B B B B <xsl:if test=" > B B B B B B B B B B B ancestor::step "> > > B B B B B B B B B B B <xsl:choose> > B B B B B B B B B B B B B B B <!-- collapsed tables in kyt1659720640909.dita --> > B B B B B B B B B B B B B B B <xsl:when test="ancestor::*[contains(@outputclass, > 'collapse')]"/> > B B B B B B B B B B B B B B B <xsl:otherwise> > B B B B B B B B B B B B B B B B B B B <xsl:value-of select="$RETURN"/> > B B B B B B B B B B B B B B B B B B B <xsl:choose> > B B B B B B B B B B B B B B B B B B B B B B B <xsl:when test="local-name()='info'"> > B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:choose> > B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:when test="child::*[1] instance > of element()"> > B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <!-- do nothing for info element > with content --> > B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:when> > B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:when test="child::*[1] instance > of text()"> > <xsl:text>+</xsl:text> > B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B <xsl:value-of select="$RETURN"/> > B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:when> > B B B B B B B B B B B B B B B B B B B B B B B B B B B </xsl:choose> > child::* selects element nodesB only I think. But do realize that the second info element also starts with a pure whitespace text node child. So, unless you strip-space, both your case have a text node child as the first child, you might want to check B B info[node()[1][normalize-space()] instance of text()]] or B B info[node()[1][normalize-space()][self::text()]] to match the info element that starts with a text node that has more than whitespace. XSL-List info and archive EasyUnsubscribe (by email) XSL-List info and archive EasyUnsubscribe (by email)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|