This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: basic xpath question
- From: Stuart Brown <sbrown at extenza dot co dot uk>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 20 Jun 2002 10:25:01 +0100
- Subject: RE: [xsl] basic xpath question
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Dominic,
You can filter a template match by using attributes in a predicate (the
square brackets coming after the element name).
So, you can create two separate templates:
<xsl:template match="section[@id='para']">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="section[@id='url']">
<a href="{@url}"><xsl:apply-templates/></a>
</xsl:template>
You could also do this in one template, using <xsl:choose> to select the
different options:
<xsl:template match="section">
<xsl:choose>
<xsl:when test="@id='para'">
<p><xsl:apply-templates></p>
</xsl:when>
<xsl:when test="@id='url'">
<a href="{@url}"><xsl:apply-templates/></a>
</xsl:when>
<xsl:when test="@id='anAlternativeChoice'">
<!-- Do whatever -->
</xsl:when>
</xsl:choose>
</xsl:template>
Hope this helps,
Stuart
> -----Original Message-----
> From: Hanlan, Dominic - Senior Developer [mailto:dhanlan@icc.co.uk]
> Sent: 20 June 2002 10:11
> To: 'XSL-List@lists.mulberrytech.com'
> Subject: [xsl] basic xpath question
>
>
> Hi,
>
> I have an xml document to be styled, if I have a construct such as
>
> <section id="para">this is text <section id="url"
> url="http://xx.yy.zz">which is to be a link</section></section>
>
> How do I, in xslt, recognise the "url" tag within the "para"
> tag, such that
> I could ouput someting like
>
> <p>this is test <a href="http://xx.yy.zz">which is to be a
> link</a></p>
>
> Regards
>
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list