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

Subject: [xsl] Checking whether a child node exists with specified attribute value.
From: Shawn Milochik <Shawn@xxxxxxxxxxxx>
Date: Wed, 22 Apr 2009 14:22:40 -0400
Hi everybody. I'm an experienced developer just getting into XSLT for
the first time. I've managed to find solutions to all my issues with
Google searches so far, but not this time. I searched the list
archive, but I didn't find what I needed, probably because I'm too new
to this to know what keywords or phrases to use.

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."

The purpose is to dynamically generate HTML for an address box from
the database. The database table contains some fields which may or may
not need to be displayed. This is decided in the XML.

Example:

Here is a set of working, related snippets I'm using, just to explain
what I'm trying to do:

XML:
      <dataElement type="text" name="txtCorpRegNumber"
label="Corporate Registration Entity No." required="yes"
dbfield="corpRegEntityNum"/>
      <dataElement type="text" name="txtFedTaxID" label="Federal Tax
ID" required="yes" dbfield="fedTaxID"/>

XSLT:
              <xsl:if test="@type='text'">
                <input type=text id="{@name}" name="{@name}" Text="{.}" />
              </xsl:if>




Here's the broken part:

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

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




Thanks,
Shawn

Current Thread