|
|
 |
| 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.
|
 |

November 4th, 2007, 12:50 PM
|
|
Registered User
|
|
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

November 4th, 2007, 01:06 PM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|

November 5th, 2007, 09:24 AM
|
|
Registered User
|
|
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|

November 5th, 2007, 09:30 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,359
Thanks: 0
Thanked 31 Times in 31 Posts
|
|
That's because Firefox doesn't support XSLT 2.0, only 1.0.
/- Sam Judson : Wrox Technical Editor -/
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |