Reputation: 1147
I have the following mark up
<ul>
<li>this is bullet list</li>
<li>this is another bullet</li>
<ul>
<li>this is embaded</li>
<li>this is embaded</li>
<ul>
<li>this is furthur embaded</li>
</ul>
</ul>
</ul>
and i need a xslt script to transform into
<xml>
<unorderlist>
<list><text>this is bullet list</text></list>
<list><para><text>this is another bullet</text>
<unorderlist>
<list><text>this is embaded</text></list>
<list><para><text>this is embaded</text>
<unorderlist>
<list><text>this is furthur embabed</text></list>
</unorderlist>
</para></list>
</unorderlist>
</para>
</list>
</unorderlist>
</xml>
Basically all the nested items should appear within the last node tag. Any hint will be really appreciated.
Upvotes: 1
Views: 152
Reputation: 5892
For example
<xsl:template match="/">
<xml>
<xsl:apply-templates/>
</xml>
</xsl:template>
<xsl:template match="ul">
<unorderlist>
<xsl:apply-templates select="li"/>
</unorderlist>
</xsl:template>
<xsl:template match="li">
<list>
<xsl:choose>
<xsl:when test="following-sibling::*[1]/self::ul">
<para>
<text>
<xsl:apply-templates/>
</text>
<xsl:apply-templates select="following-sibling::*[1]/self::ul"/>
</para>
</xsl:when>
<xsl:otherwise>
<text>
<xsl:apply-templates/>
</text>
</xsl:otherwise>
</xsl:choose>
</list>
</xsl:template>
If you want to support more complex input, use a separate mode to pull the <ul>
to preceding <li>
.
Upvotes: 2