[Top] [All Lists]

Re: [xsl] Checking whether a child node exists with specified attribute value.

2009-04-22 14:50:56
Shawn Milochik wrote:

What I want to do is check whether a node with multiple children, all
containing attribute "name," happens to have a child where the "name"
attribute is "address1."

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

      <dataElement type="address" name="addrProjectOwner"
        <addrField name="orgName" />
        <addrField name="address1" />
        <addrField name="address2" />
        <addrField name="city" />
        <addrField name="state" />
        <addrField name="zip" />

XSLT (please help fix):

(At this point I'm iterating through all <dataElement> nodes in the XML)
<xsl:if test="@type='address'">
    <xsl:if test="if an addrField in my children has name 'address1''">

      <xsl:if test="addrField[(_at_)name = 'address1']">

        <input type="text" id="txtAddress1" />
    <xsl:if test="if an addrField in my children has name 'salami''">
        <input type="text" id="txtSalami" />

You might however want to factor out stuff into templates e.g.
<xsl:template match="dataElement[(_at_)type = 'address']/addField[(_at_)name = 'address1']">
     <input type="text" id="txtAddress1"/>


        Martin Honnen

XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>