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 March 14th, 2007, 06:22 AM
Registered User
 
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Template Issue

XSLT template doesn't fetch the child nodes. please review the following XSLT template and let me know the favourable solution


[u]XSLT Template:</u>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="xml" indent="yes" cdata-section-elements="script" />
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="p">
            <xsl:if test="(@*) or (translate(text(),' ','')!='') and (normalize-space(translate(text(),' ',''))!='')">
                        <xsl:copy>
                                    <xsl:apply-templates select="node() | @*"/>
                        </xsl:copy>
            </xsl:if>
 </xsl:template>
</xsl:stylesheet>

[u]Sample XML:</u>

<ContentTwo>
<p>
<span class="066453318-09032007">
<span class="Custom_Bold">What is the Risk Management Information Services (RMIS) Division?
</span> The RMIS Division of Claim Services is a team of insurance and technology professionals dedicated to providing policyholders of member companies with products and services to meet their information needs.
</span>
</p>
<p> </p>
<p></p>
</ContentTwo>

[u]Actual Output:</u>

<ContentTwo/>

[u]Expected Output:</u>

<ContentTwo>
<p>
<span class="066453318-09032007">
<span class="Custom_Bold">What is the Risk Management Information Services (RMIS) Division?
</span> The RMIS Division of Claim Services is a team of insurance and technology professionals dedicated to providing policyholders of member companies with products and services to meet their information needs.
</span>
</p>
</ContentTwo>
 
Old March 14th, 2007, 06:32 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're only outputting a <p> element if the following condition is true:

<xsl:if test="(@*) or (translate(text(),' ','')!='') and (normalize-space(translate(text(),' ',''))!='')">


The first part @* is false for all three p elements because none of them have attributes.

The second part (translate(text(),' ','')!='') is false for all three p elements because none of them has a non-whitespace text node as a child.

Perhaps your intent was to test the string value of the <p> element rather than looking only at its immediate text nodes? That would be string(.) (or just .) in place of text().

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 14th, 2007, 06:41 AM
Registered User
 
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael Kay,
Thanks a lot for the solution.its working fine

Regards
Saravanan.K





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stumped on XSLT template hayedid XSLT 8 December 19th, 2007 02:14 PM
XSLT: ONE template to transform all the elements Behl_Neha XSLT 8 December 15th, 2007 07:31 PM
Datagrid Radio button template column issue satyajitk ASP.NET 1.0 and 1.1 Professional 6 November 26th, 2005 01:48 AM
Help Please with Template issue ckroon Dreamweaver (all versions) 2 August 12th, 2005 09:18 PM
XSLT Template error again bmains XSLT 4 December 19th, 2003 11:17 AM





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