[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Re: [docbook-apps] how to add a style attribute inside a P element? (Kindle insanity!)
Hi Robert, The mechanism in the stylesheet that lets you customize class attributes can also be used to add other attributes such as style or width. Most element templates include something like this: <xsl:apply-templates select="." mode="class.attribute"> If not, then it has this: <xsl:call-template name="common.html.attributes"> which in turn applies templates in mode="class.attribute". The default template in that mode is in html/html.xsl: <xsl:template match="*" mode="class.attribute"> <xsl:param name="class" select="local-name(.)"/> <!-- permit customization of class attributes --> <!-- Use element name by default --> <xsl:attribute name="class"> <xsl:apply-templates select="." mode="class.value"> <xsl:with-param name="class" select="$class"/> </xsl:apply-templates> </xsl:attribute> </xsl:template> As you can see, that template generates an attribute whose name is "class" and whose value is determined using mode="class.value", which is the mode I usually advise people to customize when they need to change the class value for an element. But you could expand this template to include additional <xsl:attribute> elements to generate additional attributes, such as style or width. Since this is a mode, you can write separate templates for each element that needs to generate different extra attributes, using the match attribute on the template to select a specific XPath pattern. How you determine the values from your content is up to you. As Nic suggests, role attribute could be used. Bob Stayton Sagehill Enterprises bobs@sagehill.net ----- Original Message ----- From: "Nic Gibson" <nicg@corbas.net> To: "Robert Nagle" <idiotprogrammer@gmail.com> Cc: <docbook-apps@lists.oasis-open.org> Sent: Wednesday, August 03, 2011 9:28 AM Subject: Re: [docbook-apps] how to add a style attribute inside a P element? (Kindle insanity!) Hi Robert I've been doing some of the same things you are doing here. I'm not convinced that are right about the Kindle indenting (I'm looking at some titles I worked on and we've used css classes for the indent and it's working just fine). For the width, I postprocess. I'm working on a set of scripts for a client at the moment that takes an EPUB and does some mappings for the Kindle. I may be able to make them available to you (the client is often happy for code written for them to be put into the public domain). There is no reason why you couldn't do both the things you are discussing here using a customisation though. You could use a template that operates on role attributes perhaps. nic On 3 Aug 2011, at 12:47, Robert Nagle wrote: > To add to my remarks: > > one common Kindle formatting example is to output > > to <p width=75"> or <p width=-20"> > > so it would be nice if we could have a general way to add an attribute > like "width" in some cases. > > (I don't know if it would validate as XHTML though). > > rj > > On Wed, Aug 3, 2011 at 6:36 AM, Robert Nagle <idiotprogrammer@gmail.com> wrote: >> I'm outputting a lot of epub and frequently I need to massage the >> output so that the epub can be converted into the Kindle format. >> >> One inherent problem with kindlegen is that it strips out most CSS >> code and instead adds some formatting attributes inside individual >> elements. >> >> One example. You cannot turn off indenting in Kindle unless you >> hardcode something like <p style="text-indent:0"> >> >> So I do post-processing, I would have to do a global search and replace: >> >> Change <p class="no-indent"> to <p style="text-indent:0"> in all instances. >> Change <div class="caption"><p> to <div.caption><p >> style="text-indent:0"> in all instances. >> Change <p class="pullquote"> to <p style="text-indent:0"> in all instances. >> >> I wouldn't even know how to get started to do this in customization layer. >> >> I've seen this discussion >> http://markmail.org/search/?q=class.attribute&q=list%3Aorg.oasis-open.lists.docbook-apps#query:class.attribute%20list%3Aorg.oasis-open.lists.docbook-apps%20from%3A%22Bob%20Stayton%22+page:1+mid:7jfjygrqiz5pc7bs+state:results >> where css.decoration is mentioned as well as custom class values >> http://www.sagehill.net/docbookxsl/HtmlCustomEx.html#CustomClassValues >> >> I think the section on "custom class values" seems relevant, but I >> can't follow the example. >> >> YOu would need to add a custom attribute to these elements (style) as >> well as values (text-indent:0). >> >> Do you have an idea about how to attack this problem? Thanks. >> >> -- >> Robert Nagle >> 6121 Winsome Ln #56C, Houston TX 77057-5581 >> (H) 713 893 3424/ (W) 832-251-7522 Carbon Neutral Since Jan 2010 >> http://www.robertnagle.info >> > > > > -- > Robert Nagle > 6121 Winsome Ln #56C, Houston TX 77057-5581 > (H) 713 893 3424/ (W) 832-251-7522 Carbon Neutral Since Jan 2010 > http://www.robertnagle.info > > --------------------------------------------------------------------- > To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org > For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org > Nic Gibson Corbas Consulting Digital Publishing Consultancy and Training http://www.corbas.co.uk, +44 (0)7718 906817 --------------------------------------------------------------------- To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]