Jump to content
Sign in to follow this  

New bee - XSLT issue

Recommended Posts

New bee - XSLT issue

Below is the code snippet for getting required output.
But I've to find out chapter title using on attribute value (linkend="CHAP_1").
In toc, there might be chance of missing chapter reference. In the toc section, if there is no reference for CHAP_3, then expected output should be as below.
<?xml version = '1.0' encoding = 'UTF-8'?>
<toc id="TOC">
<xref linkend="CHAP_1"/>
<xref linkend="CHAP_2"/>
<xref linkend="CHAP_4"/>
<chapter id="CHAP_1">
<title>Subject Areas</title>
<chapter id="CHAP_2">
<title>Business Questions</title>
<chapter id="CHAP_3">
<title>Job Roles</title>
<chapter id="CHAP_4">
<title>Duty Roles</title>

Expected HTML OUTPUT:(third item is missing from toc)

• Subject Areas
• Business Questions
• Duty Roles

Subject Areas

Business Questions

Job Roles

Duty Roles

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<title><xsl:value-of select="book/toc/title" /></title>
<xsl:apply-templates />
<xsl:template match="book">
<xsl:for-each select="chapter">
<li><a href="#{@id}"><xsl:value-of select="title"/></a><br/></li>

<xsl:template match="chapter">
<xsl:variable name="Id" select="@id"/>
<h2> <a name="{$Id}"><xsl:value-of select="title"/></a></h2>

Thanks in advance,

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...