RE: [xsl] Default template match

Subject: RE: [xsl] Default template match
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 30 Nov 2001 17:23:25 -0000
> So I wrote several templates for all "active" tags (that
> correspond to a special
> action), and a final "otherwise" template that simply copies
> the "non-active"
> templates to the output.
> The first question is, is it possible to define the default
> template without
> that long line such as "match="node()[name() != 'adult' and
> name() != 'object'
> and name() != 'content' and name() != 'gender']""?

yes, just set it to match="*", the default priorities will ensure that it's
only fired when none of the others match.

> Second question: my XSL is cycling through a list of persons
> in an XML doc, and
> parsing a content document. To keep the reference to the
> correct person, I am
> passing the reference to that person's data as a variable
> through all templates.
> Is this the only way to do it (certainly not! :-) ?

You haven't shown us the structure, but one would usually be able to
reference the correct person by a path, e.g. ancestor::person.

Mike Kay
>
> ...
> <xsl:template match="adult"> <!-- Output only if age > 17 -->
>   <xsl:param name="doc-ref"/> <!-- pass the reference through
> the templates
> recursively -->
>   <xsl:if test="$doc-ref/customer/age &gt; 17">
>     <xsl:apply-templates select="./*">
>       <xsl:with-param name="doc-ref" select="$doc-ref"/> <!--
> pass the reference
> through the templates recursively -->
>     </xsl:apply-templates>
>   </xsl:if>
> </xsl:template>
>
> <xsl:template match="gender"> <!-- Output only if person of
> appropriate sex -->
>   <xsl:param name="doc-ref"/> <!-- pass the reference through
> the templates
> recursively -->
>   <xsl:apply-templates select="current()[@gender =
> $doc-ref/customer/gender]/*">
>     <xsl:with-param name="doc-ref" select="$doc-ref"/> <!--
> pass the reference
> through the templates recursively -->
>   </xsl:apply-templates>
> </xsl:template>
>
> <!-- HOW DO I AVOID TO USE THIS HORRIBLE ROW, EXCLUDING ALL
> OTHER TEMPLATES? -->
> <xsl:template match="node()[name() != 'paste' and name() !=
> 'object' and name()
> != 'content' and name() != 'gender']">
>   <xsl:param name="doc-ref"/> <!-- pass the reference through
> the templates
> recursively -->
>   <xsl:copy>
>     <xsl:apply-templates select="node()">
>       <xsl:with-param name="doc-ref" select="$doc-ref"/>
>     </xsl:apply-templates>
>   </xsl:copy>
> </xsl:template>
> ...
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


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


Current Thread