xsl-list
[Top] [All Lists]

Re: [xsl] extend an xslt template defined elsewhere?

2007-10-19 14:54:11
On 10/19/07, Scott Trenda <Scott(_dot_)Trenda(_at_)oati(_dot_)net> wrote:
Looks reasonable if I can create this functionality, without modifying
the existing glossdef template:

    <dd xsl:use-attribute-sets="glossdef">
         ... internal stuff here ...
    </dd>

Like I said, you would have to add that and <xsl:attribute-set
name="glossdef"> to docbook.xsl. Then this would be your entire
stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:import href="docbook.xsl"/>
  <xsl:attribute-set name="glossdef">
    <xsl:attribute name="class">
      <xsl:value-of select="@role"/>
    </xsl:attribute>
  </xsl:attribute-set>
</xsl:stylesheet>

What you wrote (when used in an importing template) would give you the
same erratic behavior that you were seeing before, with two <dd>'s
created for each glossdef.



I don't see any attribute-sets in docbook.xsl (version 4.4)
How do I do a "copy-except-for-glossdef" routine?

I didn't expect there to be attribute-sets in there; for some reason, I
rarely see them used, even in public extensible templates. I started
writing out the copy-plus-one-other-template stylesheet, and realized
that the value of @role would not be present after the docbook.xsl
transform, so that's not a viable option. See if you can shoehorn that
attribute-set into your local copy of docbook.xsl.




If I'm understanding correctly, I would have to add the attribute-set
to docbook.xsl, and modify the existing glossary.xsl to account for
its use.

It seems my only choices are to override the template in my
customization layer completely, or modify the default behavior and
figure out a way to distribute that to all my development machines
(something I want to avoid).



~ Scott


-----Original Message-----
From: ettinger(_at_)gmail(_dot_)com [mailto:ettinger(_at_)gmail(_dot_)com] On 
Behalf Of
Anthony Ettinger
Sent: Friday, October 19, 2007 4:33 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] extend an xslt template defined elsewhere?

On 10/19/07, Scott Trenda <Scott(_dot_)Trenda(_at_)oati(_dot_)net> wrote:
Since the attribute has to go at the top of the template, you're stuck
doing another "copy-except-for-glossdef" transformation on the
docbook-transformed data, UNLESS the following is true for your
purposes
in this case:


I don't see any attribute-sets in docbook.xsl (version 4.4)
How do I do a "copy-except-for-glossdef" routine?



- Your docbook.xsl stylesheet gives glossdef's output dd an
attribute-set, like the following: (NOTE: this would be defined in
docbook.xsl)
  <xsl:attribute-set name="glossdef">
    <xsl:attribute name="attr1">attribute one</xsl:attribute>
    <xsl:attribute name="attr2">attribute two</xsl:attribute>
  </xsl:attribute-set>
  <xsl:template match="glossentry/glossdef">
    <dd xsl:use-attribute-sets="glossdef">
      ... internal stuff here ...
    </dd>
  </xsl:template>

- Your output would be valid if the glossdef-dd's class attribute was
either empty (or had a different value) in the case that the
glossdef/@role attribute was empty in the input.
  (e.g. <glossdef role=""/> => <dd class=""/>)

If this IS the case, you can do this:

<xsl:import href="docbook.xsl"/>
<xsl:attribute-set name="glossdef">
  <xsl:attribute name="class">
    <xsl:value-of select="@role"/>
  </xsl:attribute>
</xsl:attribute-set>


Attribute-sets with the same name are allowed to be declared in an
imported stylesheet and the importing stylesheet at the same time;
when
this happens, the two are merged, and if any attributes with the same
name declared in both, the one with the highest import precedence (the
importing stylesheet's one, in this case) will win.

It's a bit of a fringe case here, but definitely a good example of why
<xsl:attribute-set/> is useful. If you have control over docbook.xsl
and
frequently import it into other stylesheets, I'd recommend declaring
attribute-sets to correspond to the output elements in the main
templates, for reasons like this one. It allows you more control over
exactly what can be extended later.


~ Scott




-----Original Message-----
From: ettinger(_at_)gmail(_dot_)com [mailto:ettinger(_at_)gmail(_dot_)com] 
On Behalf Of
Anthony Ettinger
Sent: Friday, October 19, 2007 12:34 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] extend an xslt template defined elsewhere?

On 10/17/07, Scott Trenda <Scott(_dot_)Trenda(_at_)oati(_dot_)net> wrote:
<xsl:import href="docbook.xsl"/>
<xsl:template match="orderedlist">
  <xsl:if test="@role = 'html class real code goes here'">
    <xsl:apply-imports/>
  </xsl:if>
</xsl:template>

~ Scott




I'm seeing a problem with my rule:

<xsl:template match="glossentry/glossdef">
    <dd>
        <xsl:if test="@role != ''">
            <xsl:attribute name="class">
                <xsl:value-of select="@role"/>
            </xsl:attribute>
        </xsl:if>
        <xsl:apply-imports />
    </dd>
</xsl:template>



The apply-imports is creating another level of <dd> nesting in the
output...is there a way to avoid this? I still need to process the
exisiting docbook glossdef template though.




--
Anthony Ettinger
Ph: 408-656-2473
var (bonita, farley) = new Dog;
farley.barks("very loud");
bonita.barks("at strangers");

http://chovy.dyndns.org/resume/
http://utuxia.com/consulting

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
Anthony Ettinger
Ph: 408-656-2473
var (bonita, farley) = new Dog;
farley.barks("very loud");
bonita.barks("at strangers");

http://chovy.dyndns.org/resume/
http://utuxia.com/consulting

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




-- 
Anthony Ettinger
Ph: 408-656-2473
var (bonita, farley) = new Dog;
farley.barks("very loud");
bonita.barks("at strangers");

http://chovy.dyndns.org/resume/
http://utuxia.com/consulting

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--