This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Problem with simple xsl:when test expression
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Problem with simple xsl:when test expression
- From: "Mitchell, Edmund" <EMitchell at fnf dot com>
- Date: Tue, 3 Jul 2001 13:46:27 -0700
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Phil
I'm not sure I understand your question, but for this xml:
<a>
<simpleType name="MedlarsNameString">
<annotation/>
<restriction base="string">
</restriction>
</simpleType>
</a>
If I want to test that simpleType has a child element called 'restriction',
which in turn has an attribute called base whose value is equal to 'string'
then you can try:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//simpleType">
<xsl:choose>
<xsl:when test="restriction and restriction/@base='string'">
YES
</xsl:when>
<xsl:otherwise>NO</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
I hope that helps
Edmund
-----Original Message-----
From: Phil Mitchell [mailto:philip_mitchell@harvard.edu]
Sent: Tuesday, July 03, 2001 4:10 PM
To: XSL-List@lists.mulberrytech.com
Subject: [xsl] Problem with simple xsl:when test expression
I am trying to write a test expression for a when clause that will be true
when the context node has a child 'restriction' element whose 'base'
attribute is "string" -- i.e. <restriction base="string">. I think this
clause should simply be:
<xsl:choose>
<xsl:when test="./restriction[@base='string']">
</xsl:when>
</xsl:choose>
But it doesn't seem to work -- it doesn't match. What is wrong with this?
Here is the context node:
<simpleType name="MedlarsNameString">
</annotation>
<restriction base="string">
</restriction>
</simpleType>
And here is the stylesheet fragment (slightly edited -- yes, the second
choose block is meant to be nested in an otherwise block.):
<xsl:template match="xsd:simpleType">
<xsl:param name="elementName"/>
<xsl:choose>
<xsl:when test="@name='TextBlock'">
Do this....
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="./restriction[@base='string']">
Print here.
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</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