You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by "Truong, Bon" <bt...@netfish.com> on 2000/01/18 04:45:28 UTC
How to find out the existence of an attribute and child nodes
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