473,473 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

choosing element with no attribute

Hi,

Im in a dilemma and need some help.
I have an xml like this:

<animal species="dog">
<color>brown</color>
</animal>
<animal species="cat">
<color>black</color>
</animal>
<animal>
<color>no color</color>
</animal>

I want to be able to select the color with no attribute. Something
like this:
<xsl:choose>
<xsl:when test="./@species='dog'">
<value-of select=".[@species='dog']//color"/>
</xsl>
<xsl:when test="./@species='cat'">
<value-of select=".[@species='cat']//color"/>
</xsl>
....
....
</xsl:choose>

How would i get the color element under <animalwith no attribute??

Jun 5 '07 #1
2 3797
In article <11**********************@q66g2000hsg.googlegroups .com>,
anitawa <an*****@gmail.comwrote:
>I want to be able to select the color with no attribute. Something
like this:
<xsl:choose>
<xsl:when test="./@species='dog'">
You can just write "@species='dog'"
<value-of select=".[@species='dog']//color"/>
You already know that . has @species = 'dog', so you can just write
".//color" here. Or if, as in your example, <coloris the immediate
child of <animal>, you can just write "color".
</xsl>
<xsl:when test="./@species='cat'">
<value-of select=".[@species='cat']//color"/>
</xsl>
....
....
</xsl:choose>

How would i get the color element under <animalwith no attribute??
<xsl:when test="not(@species)">
<value-of select=".//color"/>

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 5 '07 #2
anitawa wrote:
I want to be able to select the color with no attribute. Something
like this:
<xsl:choose>
<xsl:when test="./@species='dog'">
the ./ is doing nothing there: you could do
@species='dog'
<value-of select=".[@species='dog']//color"/>
..[ is a syntax error in XSLT1 (it's allowed in xpath2) you just want
select="color" (you must already be on the animal element for teh
attribute test to work so you know color is the child)
</xsl>
<xsl:when test="./@species='cat'">
<value-of select=".[@species='cat']//color"/>
as above this is a syntax error in xslt1
</xsl>
....
....
</xsl:choose>

How would i get the color element under <animalwith no attribute??
select="animal[not(@*)]/color"

If you are using xslt2 then what I think you want is to replace the
xsl:choose by

<xsl:value-of
select="(animal[@species='dog'],animal[@species='cat'],animal)[1]/color"/>

ie select the color of the dog if there is one else the cat else any
other animal.
--
http://dpcarlisle.blogspot.com
Jun 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: will | last post by:
why doesnt this work? Im basically trying to get the value of the root node attribute the 'Result' attr. Which can be one of 3 things. OK, ERROR or INVALID, and then choosing between the 3 and...
0
by: Ingrid | last post by:
Am I right in thinking that datatyping at element level ie <xs:element name="num" type="xs:integer"> and specifying a choice of attribute values ie <xs:attribute name="kind"> <xs:simpleType>...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
2
by: Jordan Willms | last post by:
Hi there. I am working with lom metadata and I am a little confused with how to form the following xml element: <lom xmlns="http://www.imsglobal.org/xsd/imsmd_v1p2"...
0
by: magister | last post by:
Hello, I want to have a unique Quesiton Id key for each question under section. Not for every question in the Typed DataSet. Is there anyway I can do this...? Thanks, here is my typed...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
4
by: Eric | last post by:
Attached is an example of my question. Note the "values" attribute is optional. Also the <valuesub-element is optional. Here, the XML can contain, 1 or both or neither. I would like to allow...
3
markmcgookin
by: markmcgookin | last post by:
Hi, I have the following XML <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd"> <DateTimeLastSaved>12:12:12 1900</DateTimeLastSaved> <UserName>Bob</UserName>...
2
by: mlb5000 | last post by:
I seem to be having issues validating an XML document using my schema. Both are below: The Schema: <?xml version="1.0" encoding="UTF-8"?> <xs:schema...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.