[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Testing if first child is text or an element?

Subject: Testing if first child is text or an element?
From: "dvint@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Apr 2024 19:29:01 -0000
 Testing if first child is text or an element?
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>
  <step >
    <info>
      1 The following collection shows examples of non-checklist
      lists with nested checklists.
      <ul>
         <li>This is an unordered list item with a child
            checklist.
         </li>
      </ul>
    </info>
  </step>
  <step >
    <info>
       <p>2 The following collection shows examples of non-checklist
        lists with nested checklists.</p>
       <ul>
          <li>This is an unordered list item with a child
           checklist.
          </li>
       </ul>
   </info>
  </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.

I'm currently trying this:

<?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:ping="http://pingidentity.com"
	exclude-result-prefixes="xs"
	expand-text="yes"
	version="3.0">

<xsl:output method="text"/>

<xsl:variable name="RETURN"><xsl:text>&#x0A;</xsl:text></xsl:variable>



<xsl:template match="info" >

		<xsl:value-of select="$RETURN"/>
		<xsl:call-template name="list-block-start"/>

		<xsl:choose>
			<xsl:when test="@conref or @keyref or @conkeyref">

			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$RETURN"/>     <!-- added for info block in
					rme1659720630395.dita -->
				<xsl:apply-templates />
			</xsl:otherwise>
		</xsl:choose>

</xsl:template>



<xsl:template name="list-block-start">

		<xsl:if test="
			ancestor::step ">

			<xsl:choose>
				<!-- collapsed tables in kyt1659720640909.dita -->
				<xsl:when test="ancestor::*[contains(@outputclass, 'collapse')]"/>
				<xsl:otherwise>
					<xsl:value-of select="$RETURN"/>
					<xsl:choose>
						<xsl:when test="local-name()='info'">
							<xsl:choose>
								<xsl:when test="child::*[1] instance of element()">
									<!-- do nothing for info element with content -->
								</xsl:when>
								<xsl:when test="child::*[1] instance of text()">
									<xsl:text>+</xsl:text>
									<xsl:value-of select="$RETURN"/>
								</xsl:when>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>+</xsl:text>
						</xsl:otherwise>
					</xsl:choose>

				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>


</xsl:stylesheet>


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.