Subject: Re: [xsl] 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 |
kyt1659720640909.dita -->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
B B B B B B B B B B B B B B B <xsl:whentest="ancestor::*[contains(@outputclass,
test="local-name()='info'">'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="child::*[1] instanceB 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
do nothing for info elementof 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 <!--
test="child::*[1] instancewith 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
of text()"><xsl:value-of select="$RETURN"/>
<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
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>
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
to match the info element that starts with a text node that has more than whitespace.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Testing if first child is, dvint@xxxxxxxxx | Thread | Re: [xsl] Testing if first child is, dvint dvint@xxxxxxxx |
Re: [xsl] Testing if first child is, dvint@xxxxxxxxx | Date | Re: [xsl] Testing if first child is, dvint dvint@xxxxxxxx |
Month |