xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Boag/CAM/Lotus" <Scott_B...@lotus.com>
Subject Re: How to find out the existence of an attribute and child nodes
Date Tue, 18 Jan 2000 05:45:39 GMT

> What is the expression of the attribute "test" in "xsl:if" I can use in
> order to find out whether the element "type" contains the attribute
"name"?

<xsl:if test="type[@name]">...</xsl:if>

> How I can check whether a given node such as "element" has any child
nodes?

<xsl:if test="element[*]">...</xsl:if>

> Is it possible to call a template matching exactly the same pattern
> recursively?

Yes, sure.  Watch out for infinite loops... i.e. make sure your context is
changing.

> I am a newbie to Xalan, so I would really appreciate any help.

These are really general XSLT questions.  You would be better off posting
these type of questions to the XSL-List at mulberrytech.com
(http://www.mulberrytech.com/xsl/xsl-list/).

-scott




                                                                                         
                         
                    "Truong, Bon"                                                        
                         
                    <btruong@netf        To:     general@xml.apache.org               
                            
                    ish.com>             cc:     (bcc: Scott Boag/CAM/Lotus)          
                            
                                         Subject:     How to find out the existence of an
attribute and child      
                    01/17/00             nodes                                           
                         
                    10:45 PM                                                             
                         
                    Please                                                               
                         
                    respond to                                                           
                         
                    general                                                              
                         
                                                                                         
                         
                                                                                         
                         






Hi,

Recently, I downloaded Xalan 0.19.2.
I am looking into XSLT's capabilities to do schema transformations.
Below is a schema fragment I would like to convert to the XML doc,
which is defined in that schema fragment:

            <type name="Items">
                     <element name="Item1" minOccurs="0" maxOccurs="*">
                               <type>
                                          <element name="productDesc">
                                                    <type>
                                                              <element name
="purpose"
type="string"/>
                                                              <element name
="manufacturer"
type="string">

<type>

      <element
name="name" type="string"/>

      <element
name="region" type="string">

<type>

<element name="country" type="string"/>

<element name="city" type="string"/>

</type>

      </element>

</type>
                                                              </element>
                                                    </type>
                                          </element>
                               </type>
                     </element>
           </type>

As you can see, the element "type" doesn't contain any attribute if it is a
child node of the element "element".
What is the expression of the attribute "test" in "xsl:if" I can use in
order to find out whether the element "type" contains the attribute "name"?
How I can check whether a given node such as "element" has any child nodes?
Is it possible to call a template matching exactly the same pattern
recursively?
For example, '<element name="Item1" minOccurs="0" maxOccurs="*">' contains
a
child node '<type>'.
I would like to call a template recursively such as follows:

           <xsl:template match="type">
                         <xsl:element name="{@name}">
                               <xsl:for-each select="element">

                                    <xsl:element name="{@name}"/>
                                    <xsl:element name="{@ref}"/>
                               <!-- Is this valid?
<xsl:if test="node()=type">
                       <xsl:apply-templates
select="type"/>
                   </xsl:if>
                -->
                               </xsl:for-each>
                         </xsl:element>
               <xsl:apply-templates/>
           </xsl:template>

I am a newbie to Xalan, so I would really appreciate any help.
Thanks.

Regards

Bon








Mime
View raw message