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 | 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 Search this Thread Display Modes
  #1 (permalink)  
Old May 20th, 2013, 10:21 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Unhappy Converting straight quotes to smart quotes in xslt 1.0

Hi,
I've the below xml

HTML Code:
<para>A number of the offences set out in the Companies Ordinance are expressed to apply to "officers" of the company. "Officer" includes directors, managers and the company secretary: Companies Ordinance, s.2(1).</para>
here actually the in the input the quotes given are " but i want to convert it to smart quotes. i used the below xslt for this.

HTML Code:
<xsl:template match="para/text()">
<xsl:when test="contains(.,$quot)">
<xsl:value-of select="translate(.,$quot,'“')"/>
<xsl:value-of select="translate(substring-after(.,$quot),$quot,'”')"/>
</xsl:when>
</xsl:template>
but i am getting below ooutput.

HTML Code:
A number of the offences set out in the Companies Ordinance are expressed to apply to “officers“ of the company. “Officer“ includes directors, managers and the company secretary: Companies Ordinance, s.2(1).
but i want to get it as below.
HTML Code:
A number of the offences set out in the Companies Ordinance are expressed to apply to “officers” of the company. “Officer” includes directors, managers and the company secretary: Companies Ordinance, s.2(1).
please let me know how do i solve this.


Thanks
Reply With Quote
  #2 (permalink)  
Old May 20th, 2013, 11:19 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

Well, for starters, I wouldn't attempt this in XSLT 1.0 unless I really had to. 2.0 is so much better for this kind of task.

But whatever your programming language, you need to specify the task. Are you going to assume that the quotes match properly in pairs, and that odd-numbered instances can be replaced by opening quote and even-numbered instances by closing quote? Or do you want some smarter validation?

I think you need a recursive template something like this:

Code:
<xsl:variable name="q">"</xsl:variable>
<xsl:variable name="smart-quotes">`'</xsl:variable>
<xsl:template name="replace-quotes">
  <xsl:param name="in" select="false()"/>
  <xsl:param name="count" select="1"/>
  <xsl:choose>
    <xsl:when test="contains($in, $q)">
      <xsl:value-of select="substring-before($in, $q)"/>
      <xsl:value-of select="substring($smart-quotes, $count mod 2 + 1, 1)"/>
      <xsl:call-template name="replace-quotes">
         <xsl:with-param name="in" select="substring-after($in, $q)"/>
         <xsl:with-param name="count" select="$count + 1"/>
      </
    </
    <xsl:otherwise>
      <xsl:value-of select="$in"/>
    </
  </
</
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
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
replace straight quotes with curley quotes sunnykeerthi XSLT 1 May 6th, 2013 03:14 PM
Is there any function in XSLT to handle double quotes LeoMathew XSLT 1 September 22nd, 2010 06:03 AM
displaying single quotes and double quotes ren_123 Classic ASP Databases 2 February 22nd, 2006 02:17 PM
Double Quotes langer123 Classic ASP Basics 2 March 16th, 2005 06:22 PM
Double Quotes and Single Quotes Problem phungleon Classic ASP Basics 7 May 27th, 2004 01:44 PM



All times are GMT -4. The time now is 10:26 PM.


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