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

Subject: Re: [xsl] Checking whether a child node exists with specified attribute value.
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 22 Apr 2009 20:50:17 +0200
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="*[@name = 'address1']">



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

<xsl:if test="addrField[@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>

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



--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread