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 | 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 April 8th, 2008, 04:45 AM
Authorized User
 
Join Date: Apr 2008
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old April 8th, 2008, 05:23 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: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old April 8th, 2008, 05:49 AM
Authorized User
 
Join Date: Apr 2008
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old April 8th, 2008, 07:04 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
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



Reply With Quote
  #5 (permalink)  
Old April 8th, 2008, 07:45 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
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
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



All times are GMT -4. The time now is 08:25 AM.


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