Re: [xsl] Testing if first child is text or an element?

Subject: Re: [xsl] Testing if first child is text or an element?
From: "dvint@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Apr 2024 19:34:42 -0000
Changing to this helps

<xsl:choose>
	<xsl:when test="child::node()[1] instance of element()">
		<!-- do nothing for info element with content -->
	</xsl:when>
	<xsl:when test="child::node()[1] instance of text()">
		<xsl:text>+</xsl:text>
		<xsl:value-of select="$RETURN"/>
	</xsl:when>
</xsl:choose>

But this is detecting the whitespace between <info> and <p> as being text (which it is), how do I get it to ignore the ignorable whitespace?



On 2024-04-15 12: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>
  <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