[Home] [By Thread] [By Date] [Recent Entries]
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>
</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>
|

Cart



