[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Checking whether a child node exists with specified a

Subject: Checking whether a child node exists with specified attribute value.
From: Shawn Milochik <Shawn@xxxxxxxxxxxx>
Date: Wed, 22 Apr 2009 14:22:40 -0400
 Checking whether a child node exists with specified  a
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.