Re: [xsl] if child element does not exist stop generation

Subject: Re: [xsl] if child element does not exist stop generation
From: omprakash.v@xxxxxxxxxxxxx
Date: Tue, 3 May 2005 15:43:15 +0530
Hi,
          You can do this using:

<xsl:if test="*[self::length]"> or

<xsl:if test="*[name() = 'length']">

and

if you know it's position (n),

<xsl:if test="*[n][self::length]">


(Not tested)

Cheers,
Omprakash.V



                                                                                                                           
                    "Mikael Petterson                                                                                      
                    \(KI/EAB\)"                  To:     <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>                                 
                    <mikael.petterson@eri        cc:     (bcc: omprakash.v/Polaris)                                        
                    csson.com>                   Subject:     [xsl] if child element does not exist stop generation        
                                                                                                                           
                    05/03/2005 03:28 PM                                                                                    
                    Please respond to                                                                                      
                    xsl-list                                                                                               
                                                                                                                           
                                                                                                                           




Hi,

I have the following line in my xml:
=========================
.....
<attribute name="reserved">
   <description>
     Reference to other product
   </description>
   <readOnly/>
   <dataType>
     <sequence>
       <moRef name="Object"/>
       <length>5</length>
       <nonUnique/>
      </sequence>
    </dataType>
 </attribute>

I need to check if there is a <length>-element as child to <sequence>
otherwise I need to terminate my code generation.

All hints are very much appreciated.

Cheers,

//Mikael

This is my xsl:

 <xsl:when test="sequence">
     <xsl: if test="not(name(./*)='length')">
      <xsl:message terminate="yes">
        <!-- class name and attribute error message -->
         Attribute:<xsl:value-of select="../@name"/>
         Error:sequence missing <length> child!
       </xsl:message>
      </xsl:if>
  </xsl:when>

I get the following error message:

[java] [Fatal Error] interface.xsl:477:11: Element or attribute do not
match QName production: QName::=(NCName':')?NCName.

     [java] ** Transformer Factory error
     [java]    javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException: org.xml.sax.SAXParseException:
Element or attribute do not match QName production: QName::
=(NCName':')?NCName.
     [java] javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException: org.xml.sax.SAXParseException:
Element or attribute do not match QName production: QName::
=(NCName':')?NCName.
     [java]     at
org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:807)

     [java]     at
org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:666)

     [java]     at se.ericsson.xml2j.common.Main.main(Main.java:82)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
     [java]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

     [java]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

     [java]     at java.lang.reflect.Method.invoke(Method.java:324)
     [java]     at
org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:193)
     [java]     at
org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:130)
     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:705)
     [java]     at
org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:177)
     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:83)
     [java]     at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
     [java]     at org.apache.tools.ant.Task.perform(Task.java:364)
     [java]     at org.apache.tools.ant.Target.execute(Target.java:341)
     [java]     at
org.apache.tools.ant.Target.performTasks(Target.java:369)
     [java]     at
org.apache.tools.ant.Project.executeTarget(Project.java:1214)
     [java]     at
org.apache.tools.ant.Project.executeTargets(Project.java:1062)
     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:673)
     [java]     at org.apache.tools.ant.Main.startAnt(Main.java:188)
     [java]     at
org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
     [java]     at
org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)






This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

Current Thread