Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Choosing right element [Thread Next] Re: Choosing right elementTo: NULL Date: 5/7/2007 5:47:00 PM
> <xsl:choose>
> <xsl:when test="@timezone=$tz">
> <xsl:value-of select="."/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="."/>
> </xsl:otherwise>
> </xsl:choose>
What you've said is "If the current node's timezone attribute has the
desired value, output the node's value. If it doesn't, then still output
the node's value." Not what you wanted. Especially since value-of won't
do what you want either; it will output the concatenated text content,
which will be something like
1
15
with line breaks before and after, and with the indentation.
What you wanted was "If there is a <time> element which has the right
timezone output it, otherwise output the one with no timezone". You
didn't show us the context, but assuming that you're starting from the
parent of the <time> elements one way to write this would be:
<xsl:choose>
<xsl:when test="time[@timezone=$tz]">
<xsl:apply-templates select="time[@timezone=$tz]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="time[@timezone='']"/>
</xsl:otherwise>
</xsl:choose>
Note that here I'm also assuming you want to apply a template to the
<time> elements in order to format their content a bit more usefully.
Hope that helps.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
