Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 Display Modes
  #1 (permalink)  
Old November 4th, 2007, 12:50 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default add HTML tags via XSLT

I'm trying to use XSLT to format XML to HTML.
The thing is I need to format certain nodes by adding HTML tags to the node text
For example, I need to replace one or more strings of "B, " with "<sup>B</sup>, ".
and when it is outputed to HTML I need the tags to read as tags and put the superscript around the "B"

<stuff>item3B, item2, item1B, item4</stuff>
need to be in html
item3<sup>B</sup>, item2, item1<sup>B</sup>, item4

How to do so would be great!
thanks

Reply With Quote
  #2 (permalink)  
Old November 4th, 2007, 01:06 PM
mhkay's Avatar
Wrox Author
Points: 18,420, Level: 59
Points: 18,420, Level: 59 Points: 18,420, Level: 59 Points: 18,420, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,952
Thanks: 0
Thanked 289 Times in 284 Posts
Default

In XSLT 2.0:

<xsl:analyze-string select="stuff" regex="B">
  <xsl:matching-substring>
    <sup><xsl:value-of select="."/></sup>
  </xsl:matching-substring>
  <xsl:non-matching-substring>
    <xsl:value-of select="."/>
  </xsl:non-matching-substring>
</xsl:analyze-string>

In 1.0 it's considerably harder; you need to use recursive templates to process the string using substring-before, contains, and substring-after. There are examples in my book.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old November 5th, 2007, 09:24 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried that but I got an "Error during XSLT transformation: XSLT transformation failed." error

I'm opening the xml file on FireFox 2.0.0.9
Ideas?

my test files
XML
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="XSL_Test.xsl"?>

<NewDataSet>
  <statblock>
     <stuff>item3B, item2, item1B, item4</stuff>
  </statblock>
</NewDataSet>

XSL
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0" >

   <xsl:output method="html" />



   <xsl:template match="/">
      <html>
         <body>
            <h5>
              <xsl:analyze-string select="stuff" regex="B">
                       <xsl:matching-substring>
                                     <sup><xsl:value-of select="."/></sup>
                              </xsl:matching-substring>
                              <xsl:non-matching-substring>
                               <xsl:value-of select="."/>
                               </xsl:non-matching-substring>
                           </xsl:analyze-string>
    </h5>
 </body>
      </html>
   </xsl:template>

</xsl:stylesheet>

Reply With Quote
  #4 (permalink)  
Old November 5th, 2007, 09:30 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

That's because Firefox doesn't support XSLT 2.0, only 1.0.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
Reply


Thread Tools
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
strip html tags with xslt smiter XSLT 4 June 19th, 2012 09:34 AM
XSLT help : Interpretting HTML tags from XML kunal_kishan XSLT 1 June 26th, 2006 06:37 AM
Can I add code to title tags? wehaveasolution ASP.NET 1.0 and 1.1 Basics 0 October 10th, 2005 10:59 AM
Add XSLT transformed XML (html) on an aspx page humour XSLT 2 September 30th, 2004 06:13 AM
Dynamically Add input tags Jstmehr4u3 Javascript How-To 2 July 29th, 2003 05:03 AM



All times are GMT -4. The time now is 12:36 AM.


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