Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 17th, 2017, 01:07 AM
Registered User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2017
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default Create reference for attribute value

Hello,
I am a new bee to XSL transformation. I have been assigned with XML transformation. It would be great help if you can help on this.
Below are the sample XML and expected html output
XML:
====
<?xml version = '1.0' encoding = 'UTF-8'?>
<book>
<toc id="TOC">
<title>Contents</title>
<itemizedlist>
<listitem>
<para>
<xref linkend="CHAP_1"/>
</para>
</listitem>
<listitem>
<para>
<xref linkend="CHAP_2"/>
</para>
</listitem>
<listitem>
<para>
<xref linkend="CHAP_3"/>
</para>
</listitem>
<listitem>
<para>
<xref linkend="CHAP_4"/>
</para>
</listitem>
</itemizedlist>
</toc>
<chapter id="CHAP_1">
<title>Subject Areas</title>
</chapter>
<chapter id="CHAP_2">
<title>Business Questions</title>
</chapter>
<chapter id="CHAP_3">
<title>Job Roles</title>
</chapter>
<chapter id="CHAP_4">
<title>Duty Roles</title>
</chapter>
</book>

HTML OUTPUT: By clicking on hyper link, it should redirect to corresponding sections
Contents
Subject Areas
Business Questions
Job Roles
Duty Roles
Subject Areas
Business Questions
Job Roles
Duty Roles

Please let me know, if you need more details on this.

Thanks in advance,
Samba.
Reply With Quote
  #2 (permalink)  
Old January 17th, 2017, 05:22 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

What part of the problem did you find difficult, where did you get stuck? Can you show us your efforts so far? Without this information, you are just asking us to write the code for you, and this is not a free coding service.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old January 17th, 2017, 06:10 AM
Registered User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2017
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Below is the code snippet for getting required output. Looks working fine.
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.

Contents
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="/">
<html>
<head>
<title><xsl:value-of select="book/toc/title" /></title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="book">
<xsl:for-each select="chapter">
<ul>
<li><a href="#{@id}"><xsl:value-of select="title"/></a><br/></li>
</ul>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:template>

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

</xsl:stylesheet>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select nodes whose attribute matches another node's attribute? nikolai XSLT 5 April 18th, 2018 11:30 AM
XTDE0410: Cannot create an attribute node after creating ... WilliamYou XSLT 2 December 1st, 2012 11:48 AM
Create a reference to a .net dll from MS Access waltkrueger Pro VB.NET 2002/2003 1 November 20th, 2006 05:46 PM
Reference to existing attribute value shumba XML 1 March 15th, 2006 02:53 PM
Create Data Pump Attribute in DTS bmains SQL Server DTS 0 June 6th, 2003 08:40 AM



All times are GMT -4. The time now is 01:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.