I've below XML.
<?xml version="1.0" encoding="UTF-8"?>
<list>
<list.item>
<label>(1)</label> This is first list item)
</list.item>
<list.item><label>
<star.page>179</star.page> (2)</label>This is second)
</list.item>
<list.item><label>(3)</label>This is third)</list.item>
</list>
here my aim is. If there is star.page
, i want to break the blocks and recreate it. I mean.
If the star.page
is inside list\list.item\label
, i want to close them in the order list.item\list
print star.page
and recreate the list as list\list.item
i'm using the below XSLT.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<hmtl>
<head>
<title>New Version!</title>
</head>
<xsl:apply-templates/>
</hmtl>
</xsl:template>
<xsl:template name="orderedlist" match="list">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template name="orderitem" match="list.item">
<xsl:apply-templates select="./label/*[1][self::star.page]"/>
<li class="item">
<div class="para">
<xsl:if test="./label">
<span class="item-num">
<xsl:value-of select="./label/text()"/>
</span>
</xsl:if>
<xsl:choose>
<xsl:when test="./node()">
<xsl:apply-templates select="child::node()[not(self::label)]"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</div>
</li>
</xsl:template>
<xsl:template match="star.page">
<xsl:choose>
<xsl:when test="../../..[list] and ..[label]">
<xsl:text disable-output-escaping="yes"><![CDATA[</ol>]]></xsl:text>
<xsl:call-template name="runn_head"/>
<xsl:text disable-output-escaping="yes"><![CDATA[<ol class="eng-orderedlist orderedlist">]]></xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="runn_head"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="runn_head">
<div class="x">
<xsl:value-of select="."/>
</div>
</xsl:template>
</xsl:transform>
My current output is
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
<ol class="eng-orderedlist orderedlist">
<li class="item">
<div class="para">
<span class="item-num">(1)</span>This is first list item)
</div>
</li>
<div class="x">179</div>
<li class="item">
<div class="para">
<span class="item-num">(2)</span>This is second)
</div>
</li>
<li class="item">
<div class="para">
<span class="item-num">(3)</span>This is third)
</div>
</li>
</ol>
</hmtl>
but my Expected output is
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
<ol class="eng-orderedlist orderedlist">
<li class="item">
<div class="para">
<span class="item-num">(1)</span>This is first list item)
</div>
</li>
</ol>
<div class="x">179</div>
<ol class="eng-orderedlist orderedlist">
<li class="item">
<div class="para">
<span class="item-num">(2)</span>This is second)
</div>
</li>
<li class="item">
<div class="para">
<span class="item-num">(3)</span>This is third)
</div>
</li>
</ol>
</hmtl>
in the expected output above div class="x"
, you can see that <ol>
is closed and after printing div class="x"
, it is reopened (<ol class="eng-orderedlist orderedlist">
), please let me know where am i going wrong and how to fix it.
Here is the working demo