[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?

Subject: Re: Testing if first child is text or an element?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Apr 2024 19:35:42 -0000
Re:  Testing if first child is text or an element?
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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.