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 April 8th, 2008, 04:45 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Process all nested child node

Hi,
I want to remove node tags to extract text separated by space for each node for a given context.
<keywords>
        <acronym style="color:red;font-style:italic" class="indexterm&gt;" xmlns="http://www.w3.org/1999/xhtml">main text <acronym style="color:red;font-style:italic" class="indexterm&gt;">first text</acronym></acronym>
        <acronym style="color:red;font-style:italic" class="indexterm&gt;" xmlns="http://www.w3.org/1999/xhtml">second<acronym style="color:red;font-style:italic" class="indexterm&gt;">third</acronym></acronym>
      </keywords>

The output should be :
<Keywords><keyword>main text first text second third</keyword></keywords>

I need help on this urgrently.
Thanks in advance.
Tims

 
Old April 8th, 2008, 05:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0, try

<xsl:template match="keywords">
  <keywords><keyword>
    <xsl:value-of select=".//text()/string()"/>
  </keyword></keywords>
</xsl:template>

In 1.0, try

<xsl:template match="keywords">
  <keywords><keyword>
    <xsl:for-each select=".//text()"/>
      <xsl:value-of select="."/>
      <xsl:if test="position()!=last()">
        <xsl:text> </xsl:text>
      </xsl:if>
    </xsl:for-each>
  </keyword></keywords>
</xsl:template>

>I need help on this urgrently.

I usually refrain from answering urgent questions - experience shows that people are often in too much of a hurry to study the answer with care. I've made an exception this time, please don't prove my theory correct.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 8th, 2008, 05:49 AM
Authorized User
 
Join Date: Apr 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks Michael for the quick response. It helped me. :)

 
Old April 8th, 2008, 07:04 AM
Registered User
 
Join Date: Apr 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I wanted the html tags to reformed to xhtml standard using xslt.
Like

<html>
<li>
<p>
<p>some para</p> </p>
<li>text<li>[list]<li>some sentence </li>
<li> another text </li>
</ul>
</li></li>
</html>

Is valid in html but Invalid in xhtml
It should re formatted using xslt

<html>
<li>
<p>some para</p> </li>
<li>text[list]<li>some sentence </li>
<li> another text </li>
</ul></li>
</html>

Help will be appreciated. thanks in Advance



 
Old April 8th, 2008, 07:45 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

XSLT cannot easily process invalid XML - therefore we recommend fixing the HTML before inputting into XSLT - try something like HTMLTidy (or JTidy for its Java counterpart).

Also, this post has nothing to do with the above post. Please start a new post in the future.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Good way to select & process only one node traxwx XSLT 2 May 21st, 2007 05:08 PM
How to count the child node suri_1811 XSLT 6 November 10th, 2006 04:51 PM
Child Node Output Neal XSLT 0 June 7th, 2006 03:14 AM





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