RE: [xsl] flatten tree

Subject: RE: [xsl] flatten tree
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 21 Sep 2004 09:42:35 +0100
> but still I am not seeing through entirely and it does'nt work as
> expected, still.
> 
> *[@lang = $selectedLanguage or (not(@lang) and $defaultLanguage =
> $selectedLanguage)]
> 
> selects every element which lang attribute is set to the
> selectedLanguage or every element which has no lang attribute whenever
> the selectedLanguage matches the defaultLanguage. right?

Yes - I wasn't sure how you wanted defaultLanguage to work. I've no idea
whether this logic matches your requirements, it was only a suggestion.
> 
> this is why, i get the right result whenever
> selectedLanguage=defaultLanguage. When this is not the case I get
> nothing. hmm. strange.
> 
> so i tried
> 	<xsl:template match="*">
> 		<xsl:choose>
> 			<xsl:when test="(@lang = 
> $selectedLanguage) or (not(@lang))">
> 				<xsl:apply-imports/>
> 			</xsl:when>
> 			<xsl:otherwise>
> 				<xsl:if test="@lang = $defaultLanguage">
> 					<xsl:apply-imports/>
> 				</xsl:if>
> 			</xsl:otherwise>
> 		</xsl:choose>
> 	</xsl:template>
> which is not very beautiful, but still, out of reasons i do not
> understand, it seems that the otherwise clause gets executed, even
> when the when-clause returns true.
> 

The otherwise clause won't be executed if the when-clause returns true.
There's a bug in your logic here, but if you want help in finding it, you'll
need to provide complete stylesheet and source document, and information on
the parameter values supplied - preferably cut down to illustrate the
problem.

Michael Kay
http://www.saxonica.com/

Current Thread