Excluding xsl selection for elements with missing attributes

Terry Chilvers

Usenet Archive
Joined
Aug 29, 2003
Messages
1
Reaction score
0
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
 

Mats Kindahl

Usenet Archive
Joined
Sep 1, 2003
Messages
6
Reaction score
0
Terry Chilvers said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,224
Members
248,132
Latest member
henrywalsh

Latest Threads

Top