p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread 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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 4th, 2007, 01:06 PM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 5th, 2007, 09:30 AM
samjudson's Avatar
Friend of Wrox
Points: 4,453, Level: 28
Points: 4,453, Level: 28 Points: 4,453, Level: 28 Points: 4,453, Level: 28
Activity: 61%
Activity: 61% Activity: 61% Activity: 61%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
Default

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

/- Sam Judson : Wrox Technical Editor -/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
strip html tags with xslt smiter XSLT 2 February 13th, 2007 06:55 PM
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 06:22 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc