Re: startMode available in XSLTProcessor

"Anthony Jones" <[email protected]> Tue, 21 Aug 2007 08:16:44 +0100
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Message-ID <[email protected]>
"Jonas Sicking" <[email protected]> wrote in message
news:[email protected]...
> > and then an xsl which transforms it to a HTML table:-
> >
> > <xsl:template match="/documents">
> >     <table ...>
> >         <thead><tr>
> >             <th>
> >             .
> >             .
> >             .
> >             </th>
> >         </tr></thead>
> >         <tbody>
> >             <xsl:apply-templates select="document" />
> >         </tbody>
> >     </table>
> > <xsl:template>
> >
> > all pretty standard stuff.  However at times I may want only the tbody.
So
> > I add to the stylesheet this template:-
> >
> > <xsl:template match="/documents" mode="tbodyOnly">
> >     <tbody>
> >         <xsl:apply-templates select="document" />
> >     </tbody>
> > </xsl:template>
> >
> > Now on the MSXML processor object I set startMode = "tbodyOnly"  and
this
> > will get me the tbody only.
> >
> > I was hoping to be able to use the XSL as is.  Clearly I can't.  I guess
if
> > I add a parameter and place a choose in the top template the XSL would
> > continue to work with existing MSXML code where as in firefox I can add
a
> > parameter to acheive the same thing.
>
> Basically you are putting two different stylesheets, or two different
> transforms, into the same XSLT file. I take it the reason you're putting
> these in the same XSLT file is that there are a bunch of templates that
> are used in both transforms?
>

As I outlined it's not so much "two different transforms" as two different
modes for the same transform.  One with a thead the other without.

> Using a startMode does work, but there is no API for it in mozilla.
>
> > <xsl:template match="/documents">
> >     <xsl:choose>
> >         <xsl:when test="$startMode='tbodyOnly'">
> >             <xsl:apply-templates select="." mode="tbodyOnly" />
> >         </xsl:when>
> >         <xsl:otherwise>
> >             <xsl:apply-templates select="." mode="full" />
> >         </xsl:otherwise>
> >     </xsl:choose>
> > <xsl:template>
>
> Yup, this would work. Another way would be to create one XSLT file that
> contains all the templates, and then create two separate XSLT files that
> both <xsl:import> the templates stylesheet. That way you can use
> different URIs for when you want just the body, and when you want the
> whole thing.
>

Thats an interesting approach.

However since my code will reuse these transforms regularly I load the
stylesheet in an XSLTransform object (MSXML, in FF it would be the
XSLTProcessor object) and hold it in a variable.  Using two stylesheets
necessitates two such objects.  I'll stick with the choose, its compatible
with the existing MSXML based code and requires only a small change to the
existing XSL.

> Feel free to file a bug on adding a startMode property to the XSLT
> processor though, as that should be simple enough to add.
>
> > Would this work:-
> >
> >     <xsl:apply-templates select="." mode="{$startMode}" />
> >
> > if param defined as:-
> >
> >     <xsl:param name="startMode">full</xsl:param>
> >
> > I wonder ? hmm..
>
> Nope, that will not work as 'mode' is not defined to use
> attribute-value-templates.
>

Thanks for your help.

-- 
Anthony Jones - MVP ASP/ASP.NET