This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: finding whether starts-with or not prob
- From: Oleg Tkachenko <olegt at multiconn dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 22 May 2002 11:37:01 +0200
- Subject: Re: [xsl] finding whether starts-with or not prob
- Organization: Multiconn International
- References: <1022046276.3ceb304420523@imp2.uta.fi>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Jarkko.Moilanen@uta.fi wrote:
> I have a small prob. I'm trying to apply a template inside another one.
> The tempalte is supposed to solve whether the <DocType> value is order or
> something else and depending from the result do something in both cases.
> I have been trying to solve whats wrong, but I can't find the reason why
> it is not working. I know this is not the best solution for this case, to
> find out the content of the element, but hey... who's perfect =)
>
> XSL-FILE:(Part of it)
> <xsl:apply-templates select="Document/Information" />
> <xsl:template match="Information">
> </xsl:if>
This end tag is probably a typo, isn't it? Get rid of this and the stylesheet
will work.
> <xsl:if test="@SignStatus='Open'">
> <td bgcolor="#C4DAFE" width="50">
> <p ID="SignStatus"><font size="-1">
> <xsl:value-of select="@SignStatus" />
> </font>
> </p></td>
> </xsl:if>
> <!-- SINCE I AM "INSIDE" INFORMATION ELEMENT; I CAN CALL DIRECTLY
> THE DOCTYPE TEMPLATE, RIGHT? -->
More correctly, *the context node* is an "Information" element.
> <xsl:apply-templates select="DocType" />
>
> <td bgcolor="#C4DAFE" width="124">
> <p ID="Sender"><font size="-2">
> <xsl:value-of select="Sender" /></font>
> </p></td>
> </xsl:if>
And this end tag doesn't have counterpart start tag, which <xsl:if> do you
want to close here?
> </xsl:template>
>
> <xsl:template match="DocType">
> <xsl:if test="not(starts-with(., 'order'))">
> <td bgcolor="#C4DAFE" width="50">
> <p ID="type"><font size="-2">
> <xsl:value-of select="." /></font>
> <!-- ISNT THE DOT POINTING TO THE DOCTYPE ELEMENTS CONTENT? -->
Not exactly. "." is a short form of self::node(), which means the context node
itself, which is DocType element in the place and <xsl:value-of> instruction
is outputting string value of the first node selected by expression in
"select" attribute, so you can say <xsl:value-of select="." /> is outputting
string value of the context node.
> </p></td>
> </xsl:if>
> <xsl:if test="starts-with(., 'order')">
> <td bgcolor="#C4DAFE" width="50">
> <p ID="type"><font size="-2"><b>
> <xsl:value-of select="." /></b></font>
> </p></td>
> </xsl:if>
> </xsl:template>
btw, isn't it simpler to use a choice here?
<xsl:template match="DocType">
<td bgcolor="#C4DAFE" width="50">
<p ID="type">
<font size="-2">
<xsl:choose>
<xsl:when test="starts-with(., 'order')">
<b>
<xsl:value-of select="."/>
</b>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</font>
</p>
</td>
</xsl:template>
--
Oleg Tkachenko
Multiconn International, Israel
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list