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 September 16th, 2013, 04:31 PM
Registered User
 
Join Date: Sep 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default stripping HTML from text

I have the following XML:

Code:
<?xml version="1.0" encoding="UTF-8"?><Content><CIUser><UserId>34</UserId><ToEmailAddress>[email protected]</ToEmailAddress><CIUserUserName>BktAdmin</CIUserUserName><CINotification><CINotification><NotificationUserDisplayName>BKT Administrator</NotificationUserDisplayName><Id>b7b9ddac-d72a-4c24-9ad6-117b71fbb040</Id><CreateDate>9/16/2013 11:27:10 AM</CreateDate><NotificationUserName>BktAdmin</NotificationUserName><NotificationSentDate /><Author>mike</Author><Posting>&amp;lt;span class=&amp;quot;VisitorStart&amp;quot;&amp;gt;mike:&amp;lt;/span&amp;gt; knee patella&amp;lt;br /&amp;gt;</Posting><Body>&amp;lt;span class=&amp;quot;VisitorStart&amp;quot;&amp;gt;mike:&amp;lt;/span&amp;gt; knee patella&amp;lt;br /&amp;gt;</Body><Application>Chat</Application><Title>Chat</Title><NotificationSent>False</NotificationSent></CINotification></CINotification></CIUser></Content>
And I have the following XSLT:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match="/">
        <html>
        <head>
        <title>New HMSC Notifications</title>
        </head>
          <body>
            <div align="center"> 
            <p style="font-family: arial,  helvetica, sans-serif;font-size: 12px;color: #666666;">
              <TABLE width="100%" border="0" cellpadding="5" cellspacing="5" align="center">
                <thead bgcolor="#c9d4d9">
                  <th>Source</th>
                  <th>Date</th>
                  <th>Author</th>
                  <th>Subject</th>
                  <th>Content</th>
                </thead>
                <xsl:for-each select="Content/CIUser/CINotification/CINotification">
                  <tr>
                    <td style="white-space:nowrap">
                      <xsl:value-of select="Application"/>
                    </td>
                    <td style="white-space:nowrap">
                      <xsl:value-of select="CreateDate"/>
                    </td>
                    <td style="white-space:nowrap">
                      <xsl:value-of select="Author"/>
                    </td>
                    <td style="white-space:nowrap">
                      <xsl:value-of select="Title"/>
                    </td>
                    <td>
                      <xsl:value-of select="substring(Posting,1,100)"/>... 
                    </td>
                  </tr>
                </xsl:for-each>
              </TABLE>
            </p>
            <br/><br/>
            </div>
          </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
Here is the output of the Posting element:

&lt;span class=&quot;VisitorStart&quot;&gt;mike:&lt;/span&gt; knee patella&lt;br /&gt

The value was created by user input by a rich text editor. I would like to strip all of the tags from the output so I get:

VisitorStart Mike: knee patella

I'm limited to XSLT v1.0 in my environment, and I have reason to believe the ApacheFOP is doing the work. Can anyone help me fix my XSLT?

Thanks a ton,
--Mike
 
Old September 17th, 2013, 08:57 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The only way to do this would be to parse the string contents of the <Post> element, and hope it is valid XML. However the capabilities to parse text into a XML node tree is not built into XSLT 1.0 as standard.

You could likely write an extension method in Java that would take the string and return a node perhaps.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Stripping CRLF?? crabjoe Classic ASP Basics 7 February 26th, 2008 05:58 PM
Text To HTML sumith ASP.NET 2.0 Basics 1 October 25th, 2007 02:26 AM
Stripping last X characters fixxer XSLT 2 September 21st, 2007 05:11 PM
Stripping hyphens arholly Access 2 January 4th, 2007 09:16 AM
Ch3, P.76 - text.html/text.php not working Hostile BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 May 15th, 2004 11:09 AM





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