473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Excluding xsl selection for elements with missing attributes

In XSLT I want to select elements and output the value of a particular
attribute. However I don't want to process the element if it doesn't contain
this attribute. I'm using this to generate some code from an xsd i.e. I'm
traeting the xsd as a source xml file.
e.g.
<xs:element name="prompt" substitutionGroup="tech.char.class">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="smallcptr.char.mix"/>
<xs:element ref="co"/>
</xs:choice>
<xs:attributeGroup ref="moreinfo.attrib"/>
<xs:attributeGroup ref="common.attrib"/>
<xs:attributeGroup ref="prompt.role.attrib"/>
</xs:complexType>
</xs:element>
Here I want to output a line if the attribute "substitutionGroup" exists,
and nothing if it doesn't.
I've looked for examples, but no joy. Any ideas please?
Here's a snippet from the xslt:
<xsl:for-each select="//xs:element">
element: <xsl:value-of select="@name"/>
SubstGroup: <xsl:value-of select="@substitutionGroup"/>
but it always outputs a "SubstGroup:" line for every element.

Thanks
Terry
Jul 20 '05 #1
1 2406
"Terry Chilvers" <te************@ntlworld.com> writes:
In XSLT I want to select elements and output the value of a particular
attribute. However I don't want to process the element if it doesn't contain
this attribute. I'm using this to generate some code from an xsd i.e. I'm
traeting the xsd as a source xml file.
e.g.
<xs:element name="prompt" substitutionGroup="tech.char.class">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:group ref="smallcptr.char.mix"/>
<xs:element ref="co"/>
</xs:choice>
<xs:attributeGroup ref="moreinfo.attrib"/>
<xs:attributeGroup ref="common.attrib"/>
<xs:attributeGroup ref="prompt.role.attrib"/>
</xs:complexType>
</xs:element>
Here I want to output a line if the attribute "substitutionGroup" exists,
and nothing if it doesn't.
I've looked for examples, but no joy. Any ideas please?
Here's a snippet from the xslt:
<xsl:for-each select="//xs:element">
element: <xsl:value-of select="@name"/>
SubstGroup: <xsl:value-of select="@substitutionGroup"/>


This might work (untested):

<xsl:for-each select="//xs:element">
element: <xsl:value-of select="@name"/>
<xsl:if test="@substitutionGroup">
SubstGroup: <xsl:value-of select="@substitutionGroup"/>
</xsl:if>
</xsl:for-each>

Good luck!
Mats Kindahl
--
IAR Systems in Uppsala, Sweden.

Any opinions expressed are my own and not those of my company.

Spam prevention: Contact me at mN**********@acm.org, removing the *NO
SPAM* from the address.
Jul 20 '05 #2

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

Similar topics

4
by: Leif K-Brooks | last post by:
I'm writing a site with mod_python which will have, among other things, forums. I want to allow users to use some HTML (<em>, <strong>, <p>, etc.) on the forums, but I don't want to allow bad...
4
by: Christine McGavran | last post by:
To continue a previous thread, sort of... I have defined a schema for describing a windows-style user interface. My application correctly parses and uses that schema. I'm now trying to get that...
1
by: es | last post by:
Hello there, I'm trying to build what is in basis a screen scraper sofware that takes an url as input and produces an xml file as output.I wanted to introduce something like "document...
30
by: Blnukem | last post by:
Hi All I'm new to javascript and was wondering if someone can help me with this I want to disable my second and third drop-box if the first one is selected to "Closed" I think I'm close but just...
15
by: lawrence | last post by:
Is this the correct way to test for a method before I use it? createRange() is, I believe, an IE only method. function wrapSelectionInTag(selection, tag) { if (document.selection.createRange)...
4
by: kimimaro | last post by:
Thank you for your help I think I know what the problem is. Firstly the add_record cannot read the record.txt or something if the record.txt (in which I used it to store the details of each record)...
4
by: Samuel R. Neff | last post by:
I'm writing an xslt in vs.net 2003 and in order to get intellisense on the html content I added the default namespace declaration xmlns="http://schemas.microsoft.com/intellisense/ie5". However,...
1
by: tslettebo | last post by:
Hi all. I've read Michael Kay's "XSLT" book, and used XSLT successfully as an HTML template system at our company (using basically the "fill-in-the-blanks" pattern of XSLT use: A template...
4
by: sialater | last post by:
Hello, I realise there are a lot of topics related to this problem but many of what I have found has run cold or unresolved. What I have is an addressbook clone where there are groups which have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.