 |
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
|
|
|

December 8th, 2010, 08:47 AM
|
Authorized User
|
|
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
|
|
How to eliminate dummy element
Hi,
How to eliminate dummy element in xslt. Herewith i have pasted xml, xsl and html(The html file how it look like i inform the bottom)
XML Coding
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Preview-XML XREF b1.0.xsl"?>
<references>
<reference id="[1]">
<journal>
<journal_metadata>
<full_title></full_title>
<abbrev_title>Open Sys.</abbrev_title>
<issn></issn>
<coden></coden>
</journal_metadata>
<journal_issue>
<publication_date>
<month></month>
<day></day>
<year>2000</year>
</publication_date>
<journal_volume>
<volume>7</volume>
</journal_volume>
<issue></issue>
<special_numbering></special_numbering>
</journal_issue>
<journal_article>
<titles>bb
<title></title>
</titles>
<contributors>
<person_name sequence="first" contributor_role="author">
<given_name>V. P.</given_name>
<surname>BAlaji</surname>
<suffix></suffix>
</person_name>
<organization sequence="first|additional" contributor_role="author|editor|chair|translator"> </organization>
</contributors>
<publication_date>
<month></month>
<day></day>
<year></year>
</publication_date>
<pages>
<first_page>101</first_page>
<last_page></last_page>
<other_pages></other_pages>
</pages>
<doi_data>
<doi></doi>
<resource></resource>
</doi_data>
<comments>
<comment></comment>
</comments>
</journal_article>
<original_text>[1] V. P. BAlaji, Open Sys. <b>7</b>, 101 (2000).</original_text>
</journal>
</reference>
<references>
XSl Coding
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:output method="xml" indent="yes" />
<xsl:template match="node()">
<xsl:if test="count(descendant::text()[string-length(normalize-space(.))>0]|@*)">
<xsl:copy>
<p><xsl:apply-templates select="@*|node()" /></p>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="@*">
<xsl:copy />
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>
Html Output
Open Sys. Information Dyn.
2000
7
bb
V. P.
Belavkin
101
[1] V. P. Belavkin, Open Sys. Information Dyn.7
, 101 (2000).
Excepted html output like (For the purpose before show the element name which element the contant text hold)
<abbrev_title> Open Sys.
<year> 2000
<volume> 7
<given_name> V. P.
<surname> BAlaji
<first_page> 101
[1] V. P. BAlaji, Open Sys. 7
, 101 (2000).
Kindly look at this.
|

December 8th, 2010, 11:05 AM
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
First of all, please mark up your code samples with http://p2p.wrox.com/misc.php?do=bbcode#code so that we can better read them.
I suspect you want something like
Code:
<xsl:template match="/">
<html>
<head>
<title>Example</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="*[not(*) and normalize-space()]">
<p><xsl:value-of select="concat('<', local-name(), '>', .)"/></p>
</xsl:template>
<xsl:template match="*[not(*) and not(normalize-space())]"/>
That should output the name and contents of any leaf element containing some contents and ignore any empty elements.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|

December 9th, 2010, 02:22 AM
|
Authorized User
|
|
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi,
Thank this wil working fine. But i want small modification about that html look how i pasted the below.
XML Coding
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Preview-XML XREF b1.0.xsl"?>
<references>
<reference id="[1]">
<journal>
<journal_metadata>
<full_title></full_title>
<abbrev_title>Open Sys.</abbrev_title>
<issn></issn>
<coden></coden>
</journal_metadata>
<journal_issue>
<publication_date>
<month></month>
<day></day>
<year>2000</year>
</publication_date>
<journal_volume>
<volume>7</volume>
</journal_volume>
<issue></issue>
<special_numbering></special_numbering>
</journal_issue>
<journal_article>
<titles>bb
<title></title>
</titles>
<contributors>
<person_name sequence="first" contributor_role="author">
<given_name>V. P.</given_name>
<surname>BAlaji</surname>
<suffix></suffix>
</person_name>
<organization sequence="first|additional" contributor_role="author|editor|chair|translator"> </organization>
</contributors>
<publication_date>
<month></month>
<day></day>
<year></year>
</publication_date>
<pages>
<first_page>101</first_page>
<last_page></last_page>
<other_pages></other_pages>
</pages>
<doi_data>
<doi></doi>
<resource></resource>
</doi_data>
<comments>
<comment></comment>
</comments>
</journal_article>
<original_text>[1] V. P. BAlaji, Open Sys. <b>7</b>, 101 (2000).</original_text>
</journal>
</reference>
<references>
Output Html like
<abbrev_title>Open Sys.
<year>2000
<volume>7
<given_name>V. P.
<surname>BAlaji
<first_page>101
[1] V. P. BAlaji, Open Sys.
<b>7, 101 (2000).
The above html missed reference id no and red mark portion i want opening and closing element for bold and italic.
Journal
<reference id=[1]>
<abbrev_title>Open Sys.
<year>2000
<volume>7
<given_name>V. P.
<surname>BAlaji
<first_page>101
<original_text>[1] V. P. BAlaji, Open Sys. <b>7</b>, 101 (2000).
Kindly look at this for the above output.
Thanks.
|

December 9th, 2010, 05:01 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Please use code tags as requested. I think the code I am seeing here is not what you pasted, because you didn't mark it up correctly. This makes it difficult to understand your problem.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|

December 9th, 2010, 08:35 AM
|
Authorized User
|
|
Join Date: Nov 2010
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi,
I applied your coding it woking fine. But i want one more help for the below our coding.
XML Coding:<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Preview-XML XREF b1.0.xsl"?>
<references>
<reference id="[1]">
<journal>
<journal_metadata>
<full_title></full_title>
<abbrev_title>Open Sys.</abbrev_title>
<issn></issn>
<coden></coden>
</journal_metadata>
<journal_issue>
<publication_date>
<month></month>
<day></day>
<year>2000</year>
</publication_date>
<journal_volume>
<volume>7</volume>
</journal_volume>
<issue></issue>
<special_numbering></special_numbering>
</journal_issue>
<journal_article>
<titles>bb
<title></title>
</titles>
<contributors>
<person_name sequence="first" contributor_role="author">
<given_name>V. P.</given_name>
<surname>BAlaji</surname>
<suffix></suffix>
</person_name>
<organization sequence="first|additional" contributor_role="author|editor|chair|translator"> </organization>
</contributors>
<publication_date>
<month></month>
<day></day>
<year></year>
</publication_date>
<pages>
<first_page>101</first_page>
<last_page></last_page>
<other_pages></other_pages>
</pages>
<doi_data>
<doi></doi>
<resource></resource>
</doi_data>
<comments>
<comment></comment>
</comments>
</journal_article>
<original_text>[1] V. P. BAlaji, Open Sys. <b>7</b>, 101 (2000).</original_text>
</journal>
</reference>
<references>
XSL Coding
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:output method="xml" indent="yes" />
<xsl:template match="*[not(*) and normalize-space()]">
<p><xsl:value-of select="concat('<', local-name(), '>', .)"/></p>
</xsl:template>
<xsl:template match="*[not(*) and not(normalize-space())]"/>
</xsl:stylesheet>
Current output:
<abbrev_title> Open Sys.
<year> 2000
<volume> 7
<given_name> V. P.
<surname> BAlaji
<first_page> 101
[1] V. P. BAlaji, Open Sys. 7
, 101 (2000).
Excepted output:
Journal(I want to show the journal text)
<reference id=[1]> (I want to show reference id)
<abbrev_title>Open Sys.
<year>2000
<volume>7
<given_name>V. P.
<surname>BAlaji
<first_page>101
<original_text>[1] V. P. BAlaji, Open Sys. <b>7</b>(no need to newline. the original text element text to show single line), 101 (2000).
Pls do the needful.
|
|
 |