This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Attributes, modes and templates


>>>>> "WP" == Wendell Piez <wapiez@mulberrytech.com> writes:

WP> Hi Alex, You wrote:

>> This is the nub of my problem, exactly: for all elements called in
>> the mode (but not in the special element) I want the xsl templates
>> in the _imported_ Norman Walsh's stylesheets to be called (i.e. the
>> templates I didn't write!)

WP> Ah! Now this will be a trick.

Wendell,

Thanks for getting back to me again.

WP> For this, I'd suggest you use the <xsl:apply-imports/> element (in
WP> the spec, section 5.6). That allows you to override processing
WP> defined in the current stylesheet, in favor of rules defined in
WP> imported templates.

Actually I already use <xsl:apply-imports/> in the fragment:

  <xsl:template match="variablelist">
    <xsl:choose>
      <xsl:when test="@role='programmers'">
        <xsl:call-template name="programmer-info-mode-start"/> 
        <xsl:apply-templates mode="programmer-info-mode"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>Applying imports:</xsl:text><br/>
        <xsl:apply-imports/>

<!-- apply-imports ^^^^^^^^ -->

      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

to apply the default template when the `role' attribute is not set.  I
also tried fiddling around with <xsl:apply-imports/> in the other
template rules, but had no luck.  I always ran into the similar
problem in that I would need to specify *all* the children elements to
override, or I would never get my special element done the way I
wanted.

Incidentally, ultimately I don't want to just one `special' element
(since if I did, clearly it would be simpler to just use `role' on
that element directly), I want to override several, which is why I
only want to specify the `top' level element with the `role'
attribute.  Clearly I could do this:

<variablelist>
 <varlistentry>
   <term><corpauthor role="programmer-info">Blah</corpauthor></term>
   <listitem role="programmer-info"><para>Some text</para></listitem>
 </varlistitem>
 <varlistentry>
   <term><corpauthor role="programmer-info">Blah 2</corpauthor></term>
   <listitem role="programmer-info"><para>Some more text</para></listitem>
 </varlistitem>
</variablelist>

and everything would be fine, since none of the elements I'm
overriding would have children (only text), and hence I could write a
moded template rule for each one, but it's messy and error-prone, and
I want to be able to write:

<variablelist role="programmer-info">
 <varlistentry>
   <term><corpauthor>Blah</corpauthor></term>
   <listitem><para>Some text</para></listitem>
 </varlistitem>
 <varlistentry>
   <term><corpauthor>Blah 2</corpauthor></term>
   <listitem><para>Some more text</para></listitem>
 </varlistitem>
</variablelist>

and only override the elements corpauthor and listitem (for example)
which are the ones I want to change.

WP> In order to get your special node to process your way instead of
WP> Norman Walsh's, you could import a second stylesheet (it could
WP> contain only that template) ahead of his, so it would have a
WP> higher import precedence. (See 2.6.2 for import precedence.)

WP> In this case, you wouldn't need to use modes at all, I imagine.

WP> Since you can't write modes onto Norm's stylesheet, there is quite
WP> a wrinkle to your problem. Sorry I misunderstood your
WP> requirement. I Hope this helps--!

The best description I can think of for my requirement, is exactly
this: I want to be able to mimic the behaviour of the DSSSL fragment:

(element variablelist
  (let ((role (attribute-string (normalize "role"))))
    (if (equal? role "programmers")
        (with-mode programmer-info-mode
          (process-children))
        (process-children))))

(mode programmer-info-mode
  (element corpauthor
  ;; something special
  )
  (element listitem
  ;; something special
  ) 
)

in XSL with the minimum of fuss.  

In DSSSL, with the above fragment, if the element is listed in the
`mode' then you get that behaviour, if it's not then you always
default to the rule in the imported/included stylesheet.  Also if a
specified element (say listitem), contains children which are also not
listed in the mode, you also default back to the imported stylsheet.

i.e if you have:

 (element listitem 
    (make sequence
      ($bold-italic-seq$ (literal "Listitem: "))
      (process-children)))

and your listitem contains a ulink element, say:

 <listitem><para><ulink url="http://www.xsl.org">XSL</ulink></para></listitem>
  (1)       (2)   (3)

(1) = treated as per mode
(2) = treated by imported stylesheet
(3) = "       "   "       "

then the process-children will eventually call the ulink in the
imported stylesheets, since it's not in the mode.

In XSL it appears that that is not the semantics of processing the
modes.

Alex
-- 
Alex Lancaster * alex@santafe.edu * www.santafe.edu/~alex * 505 984-8800 x242
Santa Fe Institute (www.santafe.edu) & Swarm Development Group (www.swarm.org)


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]