Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2010, 06:14 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default how to avoid element in xsl

Dear Team,

Herewith i have pasted xml, xsl and html coding for your reference. In html blue color text(The blue text in xml element name is id and red color element name is school refid) i don't need and same the red color text. How to code this in xsl

Kindly refer the Below coding.

XML Coding
<catalog natcat="descriptive">
<id>1</id>
<catalog_name>Sanskrit</catalog_name>
<!--work start-->
<work>
<id>1</id>
<school refid="1"></school>
<work_name>Lucknow Skt. Parishad II</work_name>
<work_desc>Lucknow Skt. Parishad II. ii. p. 48 (vidhi).</work_desc>
</work>
<work>
<id>2</id>
<author refid=""></author>
<domain refid=""></domain>
<school refid="2"></school>
<work_name>Osmania Uni.</work_name>
<work_desc>Osmania Uni. p. 49.</work_desc>
</work>
<work>
<id>3</id>
<school refid="3"></school>
<work_name>SB.</work_name>
<work_desc>SB. New DC. I. iii. 52231 (in a collection).</work_desc>
</work>
<!--work end-->
</catalog>

XSL-Coding
<xsl:template match="/ncc/catalog">
<P><xsl:apply-templates></xsl:apply-templates></P>
</xsl:template>

<xsl:template match="*/catalog_name">
<span style="color:red; font-family:'SD-TTSurekh','SD-TTSurekh',sans-serif;" ><xsl:value-of select="."/></span>
</xsl:template>

HTML Output
1 Sanskrit 1 Lucknow Skt. Parishad II Lucknow Skt. Parishad II. ii. p. 48 (vidhi). 2 Osmania Uni. Osmania Uni. p. 49. 3 SB. SB. New DC. I. iii. 52231 (in a collection).
 
Old December 2nd, 2010, 06:44 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Their are some default template built into XSLT, which will always output text inside elements unless you tell it not to.

To do this you can either change your apply-templates so that it selects only those elements you want to output, or write a template to match the elements you don't want to output telling it to do nothing.

Also, you have incorrectly highlighted the two numbers that are output. The first on is the value of the catalog/id element, then second is the value of the work/id element. By default attribute values are not output.

Code:
<xsl:template match="id"><!-- will match both catalog/id and work/id - do nothing --></xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old December 2nd, 2010, 09:15 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default how to avoid element in xsl

How to avoid additional text. Kindly suggest the below html output.

Actual Output
1 Sanskrit 1 Lucknow Skt. Parishad II Lucknow Skt. Parishad II. ii. p. 48 (vidhi). 2 Osmania Uni. Osmania Uni. p. 49. 3 SB. SB. New DC. I. iii. 52231 (in a collection).

We want output like:

Sanskrit Parishad II Lucknow Skt. Parishad II. ii. p. 48 (vidhi). Osmania Uni. p. 49. 3 SB. SB. New DC. I. iii. 52231 (in a collection).
 
Old December 3rd, 2010, 07:06 AM
Authorized User
 
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
Default

Please study all below coding. i convert xml to html using xsl. our xml coding pasted below. The colored xml coding only we want the html output. kindly help.

<catalog natcat="descriptive">
<id>1</id>
<catalog_name>Sanskrit</catalog_name><!--work start-->
<work>
<id>1</id>
<school refid="1"></school>
<work_name>Lucknow Skt. Parishad II</work_name>
<work_desc>Lucknow Skt. Parishad II. ii. p. 48 (vidhi).</work_desc>
</work>
<work>
<id>2</id>
<author refid=""></author>
<domain refid=""></domain>
<school refid="2"></school>
<work_name>Osmania Uni.</work_name>
<work_desc>Osmania Uni. p. 49.</work_desc>
</work>
<work>
<id>3</id>
<school refid="3"></school>
<work_name>SB.</work_name>
<work_desc>SB. New DC. I. iii. 52231 (in a collection).</work_desc></work>
<!--work end-->
</catalog>


Current HTML output:
1 Sanskrit 1 Lucknow Skt. Parishad II Lucknow Skt. Parishad II. ii. p. 48 (vidhi). 2 Osmania Uni. Osmania Uni. p. 49. 3 SB. SB. New DC. I. iii. 52231 (in a collection).

Excepted HTML output
Sanskrit Lucknow Skt. Parishad II. ii. p. 48 (vidhi). Osmania Uni. p. 49. SB. New DC. I. iii. 52231 (in a collection).
 
Old December 3rd, 2010, 07:43 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

As I said above, if you only want to output certain elements then you need to specify them in your xsl:apply-templates select attribute.

You will probably have to write templates to handle child elements of your parent <catalog> element individually.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL(T) problems with xsl:element pan69 XSLT 3 December 13th, 2007 06:24 AM
Using Variable for xsl:element Name Belch XSLT 5 November 2nd, 2007 04:28 AM
How to use xsl:element tag??? NewToXSL XSLT 2 June 8th, 2006 05:54 PM
xsl element identification vakorde XSLT 4 May 7th, 2006 04:48 AM
Sorting element in xsl Sakubar Sathik XSLT 5 April 6th, 2006 04:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.