You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Benoit Fouche <b....@cross-systems.com> on 2000/04/12 13:35:11 UTC

XSL: howto test if an element have a child ?

Hi !
I am currently applying XSL stylesheet to an XML doc to generate WML (=HTML
for WAP)

My XML doc looks like this (and must be like this, I can't change the
structure nor the attributes...) :

<!--source.xml-->
<portal>
    <select name="sites">
        <option url="http://www.yahoo.com">Yahoo</option>
        ...
        <option url="http://www.caramail.com">Caramail</option>
    </select>

    <select name="prefixes">
        <option value="prefix">Mr.</option>
        <option value="prefix">Mrs.</option>
        ...
    </select>

    <select name="activities" multiple="true">
        <option value="activity">sport</option>
        <option value="activity">cinema</option>
        ...
    </select>
</portal>

In the tag option, you can have several differents attributes, so I would
like to make a test on those attribute like this:
I would like to do the following algorithm in XSL:

For all the "select/option" tag where the option@url DOESN'T exists I would
like to output a copy of the select tag:
    <select (with the EXACT copy of  the attributes of select tag)>
        <option value=...>
    </select>
And for the "select/option" tag where the option@url exists I just want to
output a link:
    <a href=value-of select="@url">value-of option</a>
   (without the "select" tag, here is the problem...)

My steelsheet looks like this, but doesn't work (parser crashes...) :

<xsl:template match="option[@url]">
 <a><xsl:attribute name="href"><xsl:value-of
select="@onpick"/></xsl:attribute>
      <xsl:value-of/>
 </a>
</xsl:template>

<xsl:template match="select">
 <xsl:choose>
  <xs:when test="option[@url]"/>
   <xsl:apply-templates/>
  </xsl:when>
  <xsl:otherwise>
        <xsl:copy>
            <xsl:apply-templates select="*|@*|comment()|pi()|text)"/>
        </xsl:copy>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

any help would be great !
Ben.